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

Side by Side Diff: components/arc/intent_helper/activity_icon_loader.h

Issue 2655233007: Get rid of RefCounted for ActivityIconLoader. (Closed)
Patch Set: address comments Created 3 years, 10 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
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 #ifndef COMPONENTS_ARC_INTENT_HELPER_ACTIVITY_ICON_LOADER_H_ 5 #ifndef COMPONENTS_ARC_INTENT_HELPER_ACTIVITY_ICON_LOADER_H_
6 #define COMPONENTS_ARC_INTENT_HELPER_ACTIVITY_ICON_LOADER_H_ 6 #define COMPONENTS_ARC_INTENT_HELPER_ACTIVITY_ICON_LOADER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/weak_ptr.h"
16 #include "base/threading/thread_checker.h" 17 #include "base/threading/thread_checker.h"
17 #include "components/arc/arc_service.h" 18 #include "components/arc/arc_service.h"
18 #include "components/arc/common/intent_helper.mojom.h" 19 #include "components/arc/common/intent_helper.mojom.h"
19 #include "components/arc/intent_helper/arc_intent_helper_bridge.h"
20 #include "ui/base/layout.h" 20 #include "ui/base/layout.h"
21 #include "ui/gfx/image/image.h" 21 #include "ui/gfx/image/image.h"
22 #include "url/gurl.h" 22 #include "url/gurl.h"
23 23
24 namespace arc { 24 namespace arc {
25 namespace internal {
25 26
26 // A class which retrieves an activity icon from ARC. 27 // A class which retrieves an activity icon from ARC.
27 class ActivityIconLoader : public base::RefCounted<ActivityIconLoader> { 28 class ActivityIconLoader {
28 public: 29 public:
29 struct Icons { 30 struct Icons {
30 Icons(const gfx::Image& icon16, const gfx::Image& icon20, 31 Icons(const gfx::Image& icon16, const gfx::Image& icon20,
31 const scoped_refptr<base::RefCountedData<GURL>>& icon16_dataurl); 32 const scoped_refptr<base::RefCountedData<GURL>>& icon16_dataurl);
32 Icons(const Icons& other); 33 Icons(const Icons& other);
33 ~Icons(); 34 ~Icons();
34 35
35 const gfx::Image icon16; // 16 dip 36 const gfx::Image icon16; // 16 dip
36 const gfx::Image icon20; // 20 dip 37 const gfx::Image icon20; // 20 dip
37 const scoped_refptr<base::RefCountedData<GURL>> icon16_dataurl; // as URL 38 const scoped_refptr<base::RefCountedData<GURL>> icon16_dataurl; // as URL
(...skipping 24 matching lines...) Expand all
62 // Failed. Either ARC is not supported at all or intent_helper instance 63 // Failed. Either ARC is not supported at all or intent_helper instance
63 // version is too old. 64 // version is too old.
64 FAILED_ARC_NOT_SUPPORTED, 65 FAILED_ARC_NOT_SUPPORTED,
65 }; 66 };
66 67
67 using ActivityToIconsMap = std::map<ActivityName, Icons>; 68 using ActivityToIconsMap = std::map<ActivityName, Icons>;
68 using OnIconsReadyCallback = 69 using OnIconsReadyCallback =
69 base::Callback<void(std::unique_ptr<ActivityToIconsMap>)>; 70 base::Callback<void(std::unique_ptr<ActivityToIconsMap>)>;
70 71
71 ActivityIconLoader(); 72 ActivityIconLoader();
73 ~ActivityIconLoader();
72 74
73 // Removes icons associated with |package_name| from the cache. 75 // Removes icons associated with |package_name| from the cache.
74 void InvalidateIcons(const std::string& package_name); 76 void InvalidateIcons(const std::string& package_name);
75 77
76 // Retrieves icons for the |activities| and calls |cb|. The |cb| is called 78 // Retrieves icons for the |activities| and calls |cb|. The |cb| is called
77 // back exactly once, either synchronously in the GetActivityIcons() when 79 // back exactly once, either synchronously in the GetActivityIcons() when
78 // the result is _not_ SUCCEEDED_ASYNC (i.e. all icons are already cached 80 // the result is _not_ SUCCEEDED_ASYNC (i.e. all icons are already cached
79 // locally or ARC is not ready/supported). Otherwise, the callback is run 81 // locally or ARC is not ready/supported). Otherwise, the callback is run
80 // later asynchronously with icons fetched from ARC side. 82 // later asynchronously with icons fetched from ARC side.
81 GetResult GetActivityIcons(const std::vector<ActivityName>& activities, 83 GetResult GetActivityIcons(const std::vector<ActivityName>& activities,
82 const OnIconsReadyCallback& cb); 84 const OnIconsReadyCallback& cb);
83 85
84 void OnIconsResizedForTesting(const OnIconsReadyCallback& cb, 86 void OnIconsResizedForTesting(const OnIconsReadyCallback& cb,
85 std::unique_ptr<ActivityToIconsMap> result); 87 std::unique_ptr<ActivityToIconsMap> result);
86 void AddCacheEntryForTesting(const ActivityName& activity); 88 void AddCacheEntryForTesting(const ActivityName& activity);
87 89
88 // Returns true if |result| indicates that the |cb| object passed to 90 // Returns true if |result| indicates that the |cb| object passed to
89 // GetActivityIcons() has already called. 91 // GetActivityIcons() has already called.
90 static bool HasIconsReadyCallbackRun(GetResult result); 92 static bool HasIconsReadyCallbackRun(GetResult result);
91 93
92 const ActivityToIconsMap& cached_icons_for_testing() { return cached_icons_; } 94 const ActivityToIconsMap& cached_icons_for_testing() { return cached_icons_; }
93 95
94 private: 96 private:
95 friend class base::RefCounted<ActivityIconLoader>;
96 ~ActivityIconLoader();
97
98 // A function called when the mojo IPC returns. 97 // A function called when the mojo IPC returns.
99 void OnIconsReady(std::unique_ptr<ActivityToIconsMap> cached_result, 98 void OnIconsReady(std::unique_ptr<ActivityToIconsMap> cached_result,
100 const OnIconsReadyCallback& cb, 99 const OnIconsReadyCallback& cb,
101 std::vector<mojom::ActivityIconPtr> icons); 100 std::vector<mojom::ActivityIconPtr> icons);
102 101
103 // Resizes and encodes |icons| and returns the results as ActivityToIconsMap.
104 static std::unique_ptr<ActivityToIconsMap> ResizeAndEncodeIcons(
105 std::vector<mojom::ActivityIconPtr> icons);
106
107 // A function called when ResizeIcons finishes. Append items in |result| to 102 // A function called when ResizeIcons finishes. Append items in |result| to
108 // |cached_icons_|. 103 // |cached_icons_|.
109 void OnIconsResized(std::unique_ptr<ActivityToIconsMap> cached_result, 104 void OnIconsResized(std::unique_ptr<ActivityToIconsMap> cached_result,
110 const OnIconsReadyCallback& cb, 105 const OnIconsReadyCallback& cb,
111 std::unique_ptr<ActivityToIconsMap> result); 106 std::unique_ptr<ActivityToIconsMap> result);
112 107
113 // The maximum scale factor the current platform supports. 108 // The maximum scale factor the current platform supports.
114 const ui::ScaleFactor scale_factor_; 109 const ui::ScaleFactor scale_factor_;
115 // A map which holds icons in a scale-factor independent form (gfx::Image). 110 // A map which holds icons in a scale-factor independent form (gfx::Image).
116 ActivityToIconsMap cached_icons_; 111 ActivityToIconsMap cached_icons_;
117 112
118 base::ThreadChecker thread_checker_; 113 base::ThreadChecker thread_checker_;
119 114
115 // This must come last to make sure weak pointers are invalidated first.
116 base::WeakPtrFactory<ActivityIconLoader> weak_ptr_factory_;
117
120 DISALLOW_COPY_AND_ASSIGN(ActivityIconLoader); 118 DISALLOW_COPY_AND_ASSIGN(ActivityIconLoader);
121 }; 119 };
122 120
121 } // namespace internal
123 } // namespace arc 122 } // namespace arc
124 123
125 #endif // COMPONENTS_ARC_INTENT_HELPER_ACTIVITY_ICON_LOADER_H_ 124 #endif // COMPONENTS_ARC_INTENT_HELPER_ACTIVITY_ICON_LOADER_H_
OLDNEW
« no previous file with comments | « components/arc/arc_service_manager.cc ('k') | components/arc/intent_helper/activity_icon_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698