| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/hosted_apps_counter.h" | 5 #include "chrome/browser/browsing_data/hosted_apps_counter.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/common/pref_names.h" | 11 #include "chrome/common/pref_names.h" |
| 12 #include "extensions/browser/extension_registry.h" | 12 #include "extensions/browser/extension_registry.h" |
| 13 #include "extensions/common/extension.h" | 13 #include "extensions/common/extension.h" |
| 14 | 14 |
| 15 HostedAppsCounter::HostedAppsCounter() | 15 HostedAppsCounter::HostedAppsCounter(Profile* profile) |
| 16 : pref_name_(prefs::kDeleteHostedAppsData) {} | 16 : BrowsingDataCounter(prefs::kDeleteHostedAppsData), profile_(profile) {} |
| 17 | 17 |
| 18 HostedAppsCounter::~HostedAppsCounter() {} | 18 HostedAppsCounter::~HostedAppsCounter() {} |
| 19 | 19 |
| 20 const std::string& HostedAppsCounter::GetPrefName() const { | |
| 21 return pref_name_; | |
| 22 } | |
| 23 | |
| 24 void HostedAppsCounter::Count() { | 20 void HostedAppsCounter::Count() { |
| 25 int count = 0; | 21 int count = 0; |
| 26 std::vector<std::string> names; | 22 std::vector<std::string> names; |
| 27 | 23 |
| 28 std::unique_ptr<extensions::ExtensionSet> extensions = | 24 std::unique_ptr<extensions::ExtensionSet> extensions = |
| 29 extensions::ExtensionRegistry::Get(GetProfile()) | 25 extensions::ExtensionRegistry::Get(profile_) |
| 30 ->GenerateInstalledExtensionsSet(); | 26 ->GenerateInstalledExtensionsSet(); |
| 31 | 27 |
| 32 for (const auto& extension : *extensions) { | 28 for (const auto& extension : *extensions) { |
| 33 if (extension->is_hosted_app()) | 29 if (extension->is_hosted_app()) |
| 34 names.push_back(extension->short_name()); | 30 names.push_back(extension->short_name()); |
| 35 } | 31 } |
| 36 | 32 |
| 37 count = names.size(); | 33 count = names.size(); |
| 38 | 34 |
| 39 // Give the first two names (alphabetically) as examples. | 35 // Give the first two names (alphabetically) as examples. |
| 40 std::sort(names.begin(), names.end()); | 36 std::sort(names.begin(), names.end()); |
| 41 names.resize(std::min<size_t>(2u, names.size())); | 37 names.resize(std::min<size_t>(2u, names.size())); |
| 42 | 38 |
| 43 ReportResult(base::WrapUnique(new HostedAppsResult(this, count, names))); | 39 ReportResult(base::WrapUnique(new HostedAppsResult(this, count, names))); |
| 44 } | 40 } |
| 45 | 41 |
| 46 // HostedAppsCounter::HostedAppsResult ----------------------------------------- | 42 // HostedAppsCounter::HostedAppsResult ----------------------------------------- |
| 47 | 43 |
| 48 HostedAppsCounter::HostedAppsResult::HostedAppsResult( | 44 HostedAppsCounter::HostedAppsResult::HostedAppsResult( |
| 49 const HostedAppsCounter* source, | 45 const HostedAppsCounter* source, |
| 50 ResultInt num_apps, | 46 ResultInt num_apps, |
| 51 const std::vector<std::string>& examples) | 47 const std::vector<std::string>& examples) |
| 52 : FinishedResult(source, num_apps), examples_(examples) {} | 48 : FinishedResult(source, num_apps), examples_(examples) {} |
| 53 | 49 |
| 54 HostedAppsCounter::HostedAppsResult::~HostedAppsResult() {} | 50 HostedAppsCounter::HostedAppsResult::~HostedAppsResult() {} |
| OLD | NEW |