Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / browsing_data / browsing_data_flash_lso_helper.cc
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.
4
5 #include "chrome/browser/browsing_data/browsing_data_flash_lso_helper.h"
6
7 #include <limits>
8 #include <map>
9
10 #include "base/callback.h"
11 #include "base/logging.h"
12 #include "chrome/browser/pepper_flash_settings_manager.h"
13
14 namespace {
15
16 class BrowsingDataFlashLSOHelperImpl
17     : public BrowsingDataFlashLSOHelper,
18       public PepperFlashSettingsManager::Client {
19  public:
20   explicit BrowsingDataFlashLSOHelperImpl(
21       content::BrowserContext* browser_context);
22
23   // BrowsingDataFlashLSOHelper implementation:
24   void StartFetching(const GetSitesWithFlashDataCallback& callback) override;
25   void DeleteFlashLSOsForSite(const std::string& site) override;
26
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;
32
33  private:
34   ~BrowsingDataFlashLSOHelperImpl() override;
35
36   // Asynchronously fetches and deletes data and calls us back.
37   PepperFlashSettingsManager settings_manager_;
38
39   // Identifies the request to fetch site data.
40   uint32 get_sites_with_data_request_id_;
41
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_;
45
46   // Called when we have fetched the list of sites.
47   GetSitesWithFlashDataCallback callback_;
48
49   DISALLOW_COPY_AND_ASSIGN(BrowsingDataFlashLSOHelperImpl);
50 };
51
52 BrowsingDataFlashLSOHelperImpl::BrowsingDataFlashLSOHelperImpl(
53     content::BrowserContext* browser_context)
54     : settings_manager_(this, browser_context),
55       get_sites_with_data_request_id_(0u) {
56 }
57
58 BrowsingDataFlashLSOHelperImpl::~BrowsingDataFlashLSOHelperImpl() {
59 }
60
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();
66 }
67
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;
74 }
75
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();
82 }
83
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);
92 }
93
94 }  // namespace
95
96 // static
97 BrowsingDataFlashLSOHelper* BrowsingDataFlashLSOHelper::Create(
98     content::BrowserContext* browser_context) {
99   return new BrowsingDataFlashLSOHelperImpl(browser_context);
100 }