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

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

Issue 2034543003: Retry icon fetching after intent_helper is ready (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 6 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>
(...skipping 26 matching lines...) Expand all
37 37
38 // TODO(yusukes): Add const to these variables later. At this point, 38 // TODO(yusukes): Add const to these variables later. At this point,
39 // doing so seems to confuse g++ 4.6 on builders. 39 // doing so seems to confuse g++ 4.6 on builders.
40 std::string package_name; 40 std::string package_name;
41 41
42 // Can be empty. When |activity_name| is empty, the loader tries to fetch 42 // Can be empty. When |activity_name| is empty, the loader tries to fetch
43 // the package's default icon. 43 // the package's default icon.
44 std::string activity_name; 44 std::string activity_name;
45 }; 45 };
46 46
47 enum class GetResult {
48 // Succeeded. The callback will be called asynchronously.
49 SUCCEEDED_ASYNC,
50 // Succeeded. The callback has already been called synchronously.
51 SUCCEEDED_SYNC,
52 // Failed. The intent_helper instance is not yet ready. This is a temporary
53 // error.
54 FAILED_ARC_NOT_READY,
55 // Failed. Either ARC is not supported at all or intent_helper instance
56 // version is too old.
57 FAILED_ARC_NOT_SUPPORTED,
58 };
59
47 using ActivityToIconsMap = std::map<ActivityName, Icons>; 60 using ActivityToIconsMap = std::map<ActivityName, Icons>;
48 using OnIconsReadyCallback = 61 using OnIconsReadyCallback =
49 base::Callback<void(std::unique_ptr<ActivityToIconsMap>)>; 62 base::Callback<void(std::unique_ptr<ActivityToIconsMap>)>;
50 63
51 ActivityIconLoader(); 64 ActivityIconLoader();
52 65
53 // Removes icons associated with |package_name| from the cache. 66 // Removes icons associated with |package_name| from the cache.
54 void InvalidateIcons(const std::string& package_name); 67 void InvalidateIcons(const std::string& package_name);
55 68
56 // Retrieves icons for the |activities| and calls |cb|. The |cb| is called 69 // Retrieves icons for the |activities| and calls |cb|. The |cb| is called
57 // back exactly once, either synchronously in the GetActivityIcons() when 70 // back exactly once, either synchronously in the GetActivityIcons() when
58 // all icons were already cached locally, or asynchronously with icons fetched 71 // the result is _not_ SUCCEEDED_ASYNC (i.e. all icons are already cached
59 // from ARC side. 72 // locally or ARC is not ready/supported). Otherwise, the callback is run
60 // Returns true in the former synchronous case, where everything is done. 73 // later asynchronously with icons fetched from ARC side.
61 bool GetActivityIcons(const std::vector<ActivityName>& activities, 74 GetResult GetActivityIcons(const std::vector<ActivityName>& activities,
62 const OnIconsReadyCallback& cb); 75 const OnIconsReadyCallback& cb);
63 76
64 void OnIconsResizedForTesting(const OnIconsReadyCallback& cb, 77 void OnIconsResizedForTesting(const OnIconsReadyCallback& cb,
65 std::unique_ptr<ActivityToIconsMap> result); 78 std::unique_ptr<ActivityToIconsMap> result);
66 void AddIconToCacheForTesting(const ActivityName& activity, 79 void AddIconToCacheForTesting(const ActivityName& activity,
67 const gfx::Image& image); 80 const gfx::Image& image);
68 81
82 // Returns true if |result| indicates that the |cb| object passed to
83 // GetActivityIcons() has already called.
84 static bool HasIconsReadyCallbackRun(GetResult result);
85
69 const ActivityToIconsMap& cached_icons_for_testing() { return cached_icons_; } 86 const ActivityToIconsMap& cached_icons_for_testing() { return cached_icons_; }
70 87
71 private: 88 private:
72 friend class base::RefCounted<ActivityIconLoader>; 89 friend class base::RefCounted<ActivityIconLoader>;
73 ~ActivityIconLoader(); 90 ~ActivityIconLoader();
74 91
75 // A function called when the mojo IPC returns. 92 // A function called when the mojo IPC returns.
76 void OnIconsReady(std::unique_ptr<ActivityToIconsMap> cached_result, 93 void OnIconsReady(std::unique_ptr<ActivityToIconsMap> cached_result,
77 const OnIconsReadyCallback& cb, 94 const OnIconsReadyCallback& cb,
78 mojo::Array<mojom::ActivityIconPtr> icons); 95 mojo::Array<mojom::ActivityIconPtr> icons);
(...skipping 14 matching lines...) Expand all
93 ActivityToIconsMap cached_icons_; 110 ActivityToIconsMap cached_icons_;
94 111
95 base::ThreadChecker thread_checker_; 112 base::ThreadChecker thread_checker_;
96 113
97 DISALLOW_COPY_AND_ASSIGN(ActivityIconLoader); 114 DISALLOW_COPY_AND_ASSIGN(ActivityIconLoader);
98 }; 115 };
99 116
100 } // namespace arc 117 } // namespace arc
101 118
102 #endif // COMPONENTS_ARC_INTENT_HELPER_ACTIVITY_ICON_LOADER_H_ 119 #endif // COMPONENTS_ARC_INTENT_HELPER_ACTIVITY_ICON_LOADER_H_
OLDNEW
« no previous file with comments | « chrome/browser/task_management/providers/arc/arc_process_task.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