Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_flash_lso_helper.cc
blob07cdeb08864df4855e679e3420a50e4091edd7b0
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"
7 #include <limits>
8 #include <map>
10 #include "base/callback.h"
11 #include "base/logging.h"
12 #include "chrome/browser/pepper_flash_settings_manager.h"
14 namespace {
16 class BrowsingDataFlashLSOHelperImpl
17 : public BrowsingDataFlashLSOHelper,
18 public PepperFlashSettingsManager::Client {
19 public:
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(
30 uint32 request_id,
31 const std::vector<std::string>& sites) OVERRIDE;
32 virtual void OnClearSiteDataCompleted(
33 uint32 request_id,
34 bool success) OVERRIDE;
36 private:
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());
67 callback_ = callback;
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(
80 uint32 request_id,
81 const std::vector<std::string>& sites) {
82 DCHECK_EQ(get_sites_with_data_request_id_, request_id);
83 callback_.Run(sites);
84 callback_ = GetSitesWithFlashDataCallback();
87 void BrowsingDataFlashLSOHelperImpl::OnClearSiteDataCompleted(uint32 request_id,
88 bool success) {
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 "
93 << entry->second;
94 clear_site_data_ids_.erase(entry);
97 } // namespace
99 // static
100 BrowsingDataFlashLSOHelper* BrowsingDataFlashLSOHelper::Create(
101 content::BrowserContext* browser_context) {
102 return new BrowsingDataFlashLSOHelperImpl(browser_context);