1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h"
10 #include "base/callback.h"
11 #include "base/logging.h"
12 #include "chrome/browser/pepper_flash_settings_manager.h"
16 class BrowsingDataFlashLSOHelperImpl
17 : public BrowsingDataFlashLSOHelper
,
18 public PepperFlashSettingsManager::Client
{
20 explicit BrowsingDataFlashLSOHelperImpl(
21 content::BrowserContext
* browser_context
);
23 // BrowsingDataFlashLSOHelper implementation:
24 virtual void StartFetching(
25 const GetSitesWithFlashDataCallback
& callback
) OVERRIDE
;
26 virtual void DeleteFlashLSOsForSite(const std::string
& site
) OVERRIDE
;
28 // PepperFlashSettingsManager::Client overrides:
29 virtual void OnGetSitesWithDataCompleted(
31 const std::vector
<std::string
>& sites
) OVERRIDE
;
32 virtual void OnClearSiteDataCompleted(
34 bool success
) OVERRIDE
;
37 virtual ~BrowsingDataFlashLSOHelperImpl();
39 // Asynchronously fetches and deletes data and calls us back.
40 PepperFlashSettingsManager settings_manager_
;
42 // Identifies the request to fetch site data.
43 uint32 get_sites_with_data_request_id_
;
45 // Contains the pending requests to clear site data. The key is the request
46 // ID, the value the site for which to clear data.
47 std::map
<uint32
, std::string
> clear_site_data_ids_
;
49 // Called when we have fetched the list of sites.
50 GetSitesWithFlashDataCallback callback_
;
52 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFlashLSOHelperImpl
);
55 BrowsingDataFlashLSOHelperImpl::BrowsingDataFlashLSOHelperImpl(
56 content::BrowserContext
* browser_context
)
57 : settings_manager_(this, browser_context
),
58 get_sites_with_data_request_id_(0u) {
61 BrowsingDataFlashLSOHelperImpl::~BrowsingDataFlashLSOHelperImpl() {
64 void BrowsingDataFlashLSOHelperImpl::StartFetching(
65 const GetSitesWithFlashDataCallback
& callback
) {
66 DCHECK(callback_
.is_null());
68 get_sites_with_data_request_id_
= settings_manager_
.GetSitesWithData();
71 void BrowsingDataFlashLSOHelperImpl::DeleteFlashLSOsForSite(
72 const std::string
& site
) {
73 const uint64 kClearAllData
= 0;
74 uint32 id
= settings_manager_
.ClearSiteData(
75 site
, kClearAllData
, std::numeric_limits
<uint64
>::max());
76 clear_site_data_ids_
[id
] = site
;
79 void BrowsingDataFlashLSOHelperImpl::OnGetSitesWithDataCompleted(
81 const std::vector
<std::string
>& sites
) {
82 DCHECK_EQ(get_sites_with_data_request_id_
, request_id
);
84 callback_
= GetSitesWithFlashDataCallback();
87 void BrowsingDataFlashLSOHelperImpl::OnClearSiteDataCompleted(uint32 request_id
,
89 std::map
<uint32
, std::string
>::iterator entry
=
90 clear_site_data_ids_
.find(request_id
);
91 DCHECK(entry
!= clear_site_data_ids_
.end());
92 LOG_IF(ERROR
, !success
) << "Couldn't clear Flash LSO data for "
94 clear_site_data_ids_
.erase(entry
);
100 BrowsingDataFlashLSOHelper
* BrowsingDataFlashLSOHelper::Create(
101 content::BrowserContext
* browser_context
) {
102 return new BrowsingDataFlashLSOHelperImpl(browser_context
);