Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_flash_lso_helper.cc
blobd6a0fdbe116802524a5a72ec79432a3267a7e2e7
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 void StartFetching(const GetSitesWithFlashDataCallback& callback) override;
25 void DeleteFlashLSOsForSite(const std::string& site) override;
27 // PepperFlashSettingsManager::Client overrides:
28 void OnGetSitesWithDataCompleted(
29 uint32 request_id,
30 const std::vector<std::string>& sites) override;
31 void OnClearSiteDataCompleted(uint32 request_id, bool success) override;
33 private:
34 ~BrowsingDataFlashLSOHelperImpl() override;
36 // Asynchronously fetches and deletes data and calls us back.
37 PepperFlashSettingsManager settings_manager_;
39 // Identifies the request to fetch site data.
40 uint32 get_sites_with_data_request_id_;
42 // Contains the pending requests to clear site data. The key is the request
43 // ID, the value the site for which to clear data.
44 std::map<uint32, std::string> clear_site_data_ids_;
46 // Called when we have fetched the list of sites.
47 GetSitesWithFlashDataCallback callback_;
49 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFlashLSOHelperImpl);
52 BrowsingDataFlashLSOHelperImpl::BrowsingDataFlashLSOHelperImpl(
53 content::BrowserContext* browser_context)
54 : settings_manager_(this, browser_context),
55 get_sites_with_data_request_id_(0u) {
58 BrowsingDataFlashLSOHelperImpl::~BrowsingDataFlashLSOHelperImpl() {
61 void BrowsingDataFlashLSOHelperImpl::StartFetching(
62 const GetSitesWithFlashDataCallback& callback) {
63 DCHECK(callback_.is_null());
64 callback_ = callback;
65 get_sites_with_data_request_id_ = settings_manager_.GetSitesWithData();
68 void BrowsingDataFlashLSOHelperImpl::DeleteFlashLSOsForSite(
69 const std::string& site) {
70 const uint64 kClearAllData = 0;
71 uint32 id = settings_manager_.ClearSiteData(
72 site, kClearAllData, std::numeric_limits<uint64>::max());
73 clear_site_data_ids_[id] = site;
76 void BrowsingDataFlashLSOHelperImpl::OnGetSitesWithDataCompleted(
77 uint32 request_id,
78 const std::vector<std::string>& sites) {
79 DCHECK_EQ(get_sites_with_data_request_id_, request_id);
80 callback_.Run(sites);
81 callback_ = GetSitesWithFlashDataCallback();
84 void BrowsingDataFlashLSOHelperImpl::OnClearSiteDataCompleted(uint32 request_id,
85 bool success) {
86 std::map<uint32, std::string>::iterator entry =
87 clear_site_data_ids_.find(request_id);
88 DCHECK(entry != clear_site_data_ids_.end());
89 LOG_IF(ERROR, !success) << "Couldn't clear Flash LSO data for "
90 << entry->second;
91 clear_site_data_ids_.erase(entry);
94 } // namespace
96 // static
97 BrowsingDataFlashLSOHelper* BrowsingDataFlashLSOHelper::Create(
98 content::BrowserContext* browser_context) {
99 return new BrowsingDataFlashLSOHelperImpl(browser_context);