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