OLD | NEW |
---|---|
(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 #if defined(OS_CHROMEOS) | |
14 #include "chrome/browser/ui/ash/launcher/launcher_extension_app_updater.h" | |
15 #endif | |
16 | |
17 namespace extensions { | |
18 | |
19 #if defined(OS_CHROMEOS) | |
20 | |
21 class ChromeAppIconService::Updater : public LauncherAppUpdater::Delegate { | |
msw
2017/05/08 19:59:53
Add a class comment if you keep this around.
khmel
2017/05/09 00:05:04
Done.
| |
22 public: | |
23 Updater(ChromeAppIconService* host, content::BrowserContext* context) | |
24 : host_(host), extension_app_updater_(this, context) {} | |
25 | |
26 ~Updater() override = default; | |
27 | |
28 private: | |
29 // LauncherAppUpdater::Delegate: | |
30 void OnAppUpdated(content::BrowserContext* browser_context, | |
msw
2017/05/08 19:59:53
Is this not already accomplished by ChromeAppIconS
khmel
2017/05/09 00:05:04
No, LauncherExtensionAppUpdater in ChromeOS additi
msw
2017/05/10 19:05:21
Why not simply make ChromeAppIconService inherit f
khmel
2017/05/11 02:13:48
I did not do this because introduce heavy logic in
| |
31 const std::string& app_id) override { | |
32 host_->OnAppUpdated(app_id); | |
33 } | |
34 | |
35 // Unowned pointer. | |
36 ChromeAppIconService* const host_; | |
37 | |
38 LauncherExtensionAppUpdater extension_app_updater_; | |
msw
2017/05/08 19:59:53
What is this member used for? It's instantiated bu
khmel
2017/05/09 00:05:04
It used like: extension_app_updater_(this, context
| |
39 | |
40 DISALLOW_COPY_AND_ASSIGN(Updater); | |
41 }; | |
42 | |
43 #endif | |
44 | |
45 // static | |
46 ChromeAppIconService* ChromeAppIconService::Get( | |
47 content::BrowserContext* context) { | |
48 return ChromeAppIconServiceFactory::GetInstance()->GetForBrowserContext( | |
49 context); | |
50 } | |
51 | |
52 ChromeAppIconService::ChromeAppIconService(content::BrowserContext* context) | |
53 : context_(context), observer_(this), weak_ptr_factory_(this) { | |
54 #if defined(OS_CHROMEOS) | |
55 app_updater_ = base::MakeUnique<Updater>(this, context); | |
56 #endif | |
57 | |
58 observer_.Add(ExtensionRegistry::Get(context_)); | |
59 } | |
60 | |
61 ChromeAppIconService::~ChromeAppIconService() = default; | |
62 | |
63 void ChromeAppIconService::Shutdown() { | |
64 #if defined(OS_CHROMEOS) | |
65 app_updater_.reset(); | |
66 #endif | |
67 } | |
68 | |
69 std::unique_ptr<ChromeAppIcon> ChromeAppIconService::CreateIcon( | |
70 ChromeAppIconDelegate* delegate, | |
71 const std::string& app_id, | |
72 int resource_size_in_dip) { | |
73 std::unique_ptr<ChromeAppIcon> icon = base::MakeUnique<ChromeAppIcon>( | |
74 delegate, context_, | |
75 base::Bind(&ChromeAppIconService::OnIconDestroyed, | |
76 weak_ptr_factory_.GetWeakPtr()), | |
77 app_id, resource_size_in_dip); | |
78 | |
79 icon_map_[icon->app_id()].insert(icon.get()); | |
80 return icon; | |
81 } | |
82 | |
83 void ChromeAppIconService::OnExtensionLoaded( | |
84 content::BrowserContext* browser_context, | |
85 const Extension* extension) { | |
86 OnAppUpdated(extension->id()); | |
87 } | |
88 | |
89 void ChromeAppIconService::OnExtensionUnloaded( | |
90 content::BrowserContext* browser_context, | |
91 const Extension* extension, | |
92 UnloadedExtensionReason reason) { | |
93 OnAppUpdated(extension->id()); | |
94 } | |
95 | |
96 void ChromeAppIconService::OnAppUpdated(const std::string& app_id) { | |
97 IconMap::const_iterator it = icon_map_.find(app_id); | |
98 if (it == icon_map_.end()) | |
99 return; | |
100 for (auto* icon : it->second) | |
101 icon->UpdateIcon(); | |
102 } | |
103 | |
104 void ChromeAppIconService::OnIconDestroyed(ChromeAppIcon* icon) { | |
105 DCHECK(icon); | |
106 IconMap::iterator it = icon_map_.find(icon->app_id()); | |
107 DCHECK(it != icon_map_.end()); | |
108 it->second.erase(icon); | |
109 if (it->second.empty()) | |
110 icon_map_.erase(it); | |
111 } | |
112 | |
113 } // namespace extensions | |
OLD | NEW |