Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: chrome/browser/extensions/chrome_app_icon_service.cc

Issue 2819413003: Refactor extension app icon. (Closed)
Patch Set: nit Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 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/extensions/chrome_app_icon_service.h"
6
7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h"
9 #include "chrome/browser/extensions/chrome_app_icon.h"
10 #include "chrome/browser/extensions/chrome_app_icon_service_factory.h"
11 #include "extensions/browser/extension_registry.h"
12
13 namespace extensions {
14
15 // static
16 ChromeAppIconService* ChromeAppIconService::Get(
17 content::BrowserContext* context) {
18 return ChromeAppIconServiceFactory::GetInstance()->GetForBrowserContext(
19 context);
20 }
21
22 ChromeAppIconService::ChromeAppIconService(content::BrowserContext* context)
23 : context_(context), observer_(this), weak_ptr_factory_(this) {
24 #if defined(OS_CHROMEOS)
25 app_updater_ = base::MakeUnique<LauncherExtensionAppUpdater>(this, context);
26 #endif
27
28 observer_.Add(ExtensionRegistry::Get(context_));
29 }
30
31 ChromeAppIconService::~ChromeAppIconService() = default;
32
33 void ChromeAppIconService::Shutdown() {
34 #if defined(OS_CHROMEOS)
35 app_updater_.reset();
36 #endif
37 }
38
39 std::unique_ptr<ChromeAppIcon> ChromeAppIconService::CreateIcon(
40 ChromeAppIconDelegate* delegate,
41 const std::string& app_id,
42 int resource_size_in_dip) {
43 std::unique_ptr<ChromeAppIcon> icon = base::MakeUnique<ChromeAppIcon>(
44 delegate, context_,
45 base::Bind(&ChromeAppIconService::OnIconDestroyed,
46 weak_ptr_factory_.GetWeakPtr()),
47 app_id, resource_size_in_dip);
48
49 icon_map_[icon->app_id()].insert(icon.get());
50 return icon;
51 }
52
53 void ChromeAppIconService::OnExtensionLoaded(
54 content::BrowserContext* browser_context,
55 const Extension* extension) {
56 OnAppUpdated(extension->id());
57 }
58
59 void ChromeAppIconService::OnExtensionUnloaded(
60 content::BrowserContext* browser_context,
61 const Extension* extension,
62 UnloadedExtensionReason reason) {
63 OnAppUpdated(extension->id());
64 }
65
66 #if defined(OS_CHROMEOS)
67 void ChromeAppIconService::OnAppUpdated(
68 content::BrowserContext* browser_context,
69 const std::string& app_id) {
70 OnAppUpdated(app_id);
71 }
72 #endif
73
74 void ChromeAppIconService::OnAppUpdated(const std::string& app_id) {
75 IconMap::const_iterator it = icon_map_.find(app_id);
76 if (it == icon_map_.end())
77 return;
78 for (auto* icon : it->second)
79 icon->UpdateIcon();
80 }
81
82 void ChromeAppIconService::OnIconDestroyed(ChromeAppIcon* icon) {
83 DCHECK(icon);
84 IconMap::iterator it = icon_map_.find(icon->app_id());
85 DCHECK(it != icon_map_.end());
86 it->second.erase(icon);
87 if (it->second.empty())
88 icon_map_.erase(it);
89 }
90
91 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/chrome_app_icon_service.h ('k') | chrome/browser/extensions/chrome_app_icon_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698