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