OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h" | 5 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "chrome/browser/pepper_flash_settings_manager.h" | 15 #include "chrome/browser/pepper_flash_settings_manager.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 class BrowsingDataFlashLSOHelperImpl | 19 class BrowsingDataFlashLSOHelperImpl |
20 : public BrowsingDataFlashLSOHelper, | 20 : public BrowsingDataFlashLSOHelper, |
21 public PepperFlashSettingsManager::Client { | 21 public PepperFlashSettingsManager::Client { |
22 public: | 22 public: |
23 explicit BrowsingDataFlashLSOHelperImpl( | 23 explicit BrowsingDataFlashLSOHelperImpl( |
24 content::BrowserContext* browser_context); | 24 content::BrowserContext* browser_context); |
25 | 25 |
26 // BrowsingDataFlashLSOHelper implementation: | 26 // BrowsingDataFlashLSOHelper implementation: |
27 void StartFetching(const GetSitesWithFlashDataCallback& callback) override; | 27 void StartFetching(const GetSitesWithFlashDataCallback& callback) override; |
28 void DeleteFlashLSOsForSite(const std::string& site) override; | 28 void DeleteFlashLSOsForSite(const std::string& site, |
| 29 const base::Closure& callback) override; |
29 | 30 |
30 // PepperFlashSettingsManager::Client overrides: | 31 // PepperFlashSettingsManager::Client overrides: |
31 void OnGetSitesWithDataCompleted( | 32 void OnGetSitesWithDataCompleted( |
32 uint32_t request_id, | 33 uint32_t request_id, |
33 const std::vector<std::string>& sites) override; | 34 const std::vector<std::string>& sites) override; |
34 void OnClearSiteDataCompleted(uint32_t request_id, bool success) override; | 35 void OnClearSiteDataCompleted(uint32_t request_id, bool success) override; |
35 | 36 |
36 private: | 37 private: |
| 38 struct DeleteFlashLSOTask { |
| 39 DeleteFlashLSOTask() {} |
| 40 DeleteFlashLSOTask(const std::string& site, const base::Closure& callback) |
| 41 : site(site), callback(callback) {} |
| 42 |
| 43 std::string site; |
| 44 base::Closure callback; |
| 45 }; |
| 46 |
37 ~BrowsingDataFlashLSOHelperImpl() override; | 47 ~BrowsingDataFlashLSOHelperImpl() override; |
38 | 48 |
39 // Asynchronously fetches and deletes data and calls us back. | 49 // Asynchronously fetches and deletes data and calls us back. |
40 PepperFlashSettingsManager settings_manager_; | 50 PepperFlashSettingsManager settings_manager_; |
41 | 51 |
42 // Identifies the request to fetch site data. | 52 // Identifies the request to fetch site data. |
43 uint32_t get_sites_with_data_request_id_; | 53 uint32_t get_sites_with_data_request_id_; |
44 | 54 |
45 // Contains the pending requests to clear site data. The key is the request | 55 // Contains the pending requests to clear site data. The key is the request |
46 // ID, the value the site for which to clear data. | 56 // ID, the value is the site for which to clear data and the callback to be |
47 std::map<uint32_t, std::string> clear_site_data_ids_; | 57 // called upon completion. |
| 58 std::map<uint32_t, DeleteFlashLSOTask> clear_site_data_ids_; |
48 | 59 |
49 // Called when we have fetched the list of sites. | 60 // Called when we have fetched the list of sites. |
50 GetSitesWithFlashDataCallback callback_; | 61 GetSitesWithFlashDataCallback callback_; |
51 | 62 |
52 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFlashLSOHelperImpl); | 63 DISALLOW_COPY_AND_ASSIGN(BrowsingDataFlashLSOHelperImpl); |
53 }; | 64 }; |
54 | 65 |
55 BrowsingDataFlashLSOHelperImpl::BrowsingDataFlashLSOHelperImpl( | 66 BrowsingDataFlashLSOHelperImpl::BrowsingDataFlashLSOHelperImpl( |
56 content::BrowserContext* browser_context) | 67 content::BrowserContext* browser_context) |
57 : settings_manager_(this, browser_context), | 68 : settings_manager_(this, browser_context), |
58 get_sites_with_data_request_id_(0u) { | 69 get_sites_with_data_request_id_(0u) { |
59 } | 70 } |
60 | 71 |
61 BrowsingDataFlashLSOHelperImpl::~BrowsingDataFlashLSOHelperImpl() { | 72 BrowsingDataFlashLSOHelperImpl::~BrowsingDataFlashLSOHelperImpl() { |
62 } | 73 } |
63 | 74 |
64 void BrowsingDataFlashLSOHelperImpl::StartFetching( | 75 void BrowsingDataFlashLSOHelperImpl::StartFetching( |
65 const GetSitesWithFlashDataCallback& callback) { | 76 const GetSitesWithFlashDataCallback& callback) { |
66 DCHECK(callback_.is_null()); | 77 DCHECK(callback_.is_null()); |
67 callback_ = callback; | 78 callback_ = callback; |
68 get_sites_with_data_request_id_ = settings_manager_.GetSitesWithData(); | 79 get_sites_with_data_request_id_ = settings_manager_.GetSitesWithData(); |
69 } | 80 } |
70 | 81 |
71 void BrowsingDataFlashLSOHelperImpl::DeleteFlashLSOsForSite( | 82 void BrowsingDataFlashLSOHelperImpl::DeleteFlashLSOsForSite( |
72 const std::string& site) { | 83 const std::string& site, const base::Closure& callback) { |
73 const uint64_t kClearAllData = 0; | 84 const uint64_t kClearAllData = 0; |
74 uint32_t id = settings_manager_.ClearSiteData( | 85 uint32_t id = settings_manager_.ClearSiteData( |
75 site, kClearAllData, std::numeric_limits<uint64_t>::max()); | 86 site, kClearAllData, std::numeric_limits<uint64_t>::max()); |
76 clear_site_data_ids_[id] = site; | 87 clear_site_data_ids_[id] = DeleteFlashLSOTask(site, callback); |
77 } | 88 } |
78 | 89 |
79 void BrowsingDataFlashLSOHelperImpl::OnGetSitesWithDataCompleted( | 90 void BrowsingDataFlashLSOHelperImpl::OnGetSitesWithDataCompleted( |
80 uint32_t request_id, | 91 uint32_t request_id, |
81 const std::vector<std::string>& sites) { | 92 const std::vector<std::string>& sites) { |
82 DCHECK_EQ(get_sites_with_data_request_id_, request_id); | 93 DCHECK_EQ(get_sites_with_data_request_id_, request_id); |
83 callback_.Run(sites); | 94 callback_.Run(sites); |
84 callback_ = GetSitesWithFlashDataCallback(); | 95 callback_ = GetSitesWithFlashDataCallback(); |
85 } | 96 } |
86 | 97 |
87 void BrowsingDataFlashLSOHelperImpl::OnClearSiteDataCompleted( | 98 void BrowsingDataFlashLSOHelperImpl::OnClearSiteDataCompleted( |
88 uint32_t request_id, | 99 uint32_t request_id, |
89 bool success) { | 100 bool success) { |
90 std::map<uint32_t, std::string>::iterator entry = | 101 std::map<uint32_t, DeleteFlashLSOTask>::iterator entry = |
91 clear_site_data_ids_.find(request_id); | 102 clear_site_data_ids_.find(request_id); |
92 DCHECK(entry != clear_site_data_ids_.end()); | 103 DCHECK(entry != clear_site_data_ids_.end()); |
93 LOG_IF(ERROR, !success) << "Couldn't clear Flash LSO data for " | 104 LOG_IF(ERROR, !success) << "Couldn't clear Flash LSO data for " |
94 << entry->second; | 105 << entry->second.site; |
| 106 if (!entry->second.callback.is_null()) |
| 107 entry->second.callback.Run(); |
95 clear_site_data_ids_.erase(entry); | 108 clear_site_data_ids_.erase(entry); |
96 } | 109 } |
97 | 110 |
98 } // namespace | 111 } // namespace |
99 | 112 |
100 // static | 113 // static |
101 BrowsingDataFlashLSOHelper* BrowsingDataFlashLSOHelper::Create( | 114 BrowsingDataFlashLSOHelper* BrowsingDataFlashLSOHelper::Create( |
102 content::BrowserContext* browser_context) { | 115 content::BrowserContext* browser_context) { |
103 return new BrowsingDataFlashLSOHelperImpl(browser_context); | 116 return new BrowsingDataFlashLSOHelperImpl(browser_context); |
104 } | 117 } |
OLD | NEW |