OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_WEBAPPS_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_APP_REGISTRY_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_WEBAPPS_REGISTRY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_APP_REGISTRY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
14 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "chrome/browser/google_apis/gdata_errorcode.h" | 15 #include "chrome/browser/google_apis/gdata_errorcode.h" |
16 #include "chrome/browser/google_apis/gdata_wapi_parser.h" | 16 #include "chrome/browser/google_apis/gdata_wapi_parser.h" |
17 #include "googleurl/src/gurl.h" | 17 #include "googleurl/src/gurl.h" |
18 | 18 |
19 namespace base { | 19 namespace base { |
20 class FilePath; | 20 class FilePath; |
21 } // namespace base | 21 } // namespace base |
22 | 22 |
23 namespace google_apis { | 23 namespace google_apis { |
24 class AppList; | 24 class AppList; |
25 } // namespace AppList | 25 } // namespace AppList |
26 | 26 |
27 namespace drive { | 27 namespace drive { |
28 | 28 |
29 class JobScheduler; | 29 class JobScheduler; |
30 | 30 |
31 // Data structure that defines WebApp | 31 // Data structure that defines Drive app. See |
32 struct DriveWebAppInfo { | 32 // https://chrome.google.com/webstore/category/collection/drive_apps for |
33 DriveWebAppInfo(const std::string& app_id, | 33 // Drive apps available on the webstore. |
34 struct DriveAppInfo { | |
35 DriveAppInfo(const std::string& app_id, | |
34 const google_apis::InstalledApp::IconList& app_icons, | 36 const google_apis::InstalledApp::IconList& app_icons, |
hashimoto
2013/05/28 03:59:47
nit: Indent
satorux1
2013/05/28 04:05:16
Done.
| |
35 const google_apis::InstalledApp::IconList& document_icons, | 37 const google_apis::InstalledApp::IconList& document_icons, |
36 const std::string& web_store_id, | 38 const std::string& web_store_id, |
37 const string16& app_name, | 39 const string16& app_name, |
38 const string16& object_type, | 40 const string16& object_type, |
39 bool is_primary_selector); | 41 bool is_primary_selector); |
40 ~DriveWebAppInfo(); | 42 ~DriveAppInfo(); |
41 | 43 |
42 // Drive app id | 44 // Drive app id. |
43 std::string app_id; | 45 std::string app_id; |
44 // Drive application icon URLs for this app, paired with their size (length of | 46 // Drive application icon URLs for this app, paired with their size (length of |
45 // a side in pixels). | 47 // a side in pixels). |
46 google_apis::InstalledApp::IconList app_icons; | 48 google_apis::InstalledApp::IconList app_icons; |
47 // Drive document icon URLs for this app, paired with their size (length of | 49 // Drive document icon URLs for this app, paired with their size (length of |
48 // a side in pixels). | 50 // a side in pixels). |
49 google_apis::InstalledApp::IconList document_icons; | 51 google_apis::InstalledApp::IconList document_icons; |
50 // Web store id/extension id; | 52 // Web store id/extension id; |
51 std::string web_store_id; | 53 std::string web_store_id; |
52 // WebApp name. | 54 // App name. |
53 string16 app_name; | 55 string16 app_name; |
54 // Object (file) type description handled by this app. | 56 // Object (file) type description handled by this app. |
55 string16 object_type; | 57 string16 object_type; |
56 // Is app the primary selector for file (default open action). | 58 // Is app the primary selector for file (default open action). |
57 bool is_primary_selector; | 59 bool is_primary_selector; |
58 }; | 60 }; |
59 | 61 |
60 // Keeps the track of installed drive web application and provider in-memory. | 62 // Keeps the track of installed drive applications in-memory. |
61 class DriveWebAppsRegistry { | 63 class DriveAppRegistry { |
62 public: | 64 public: |
63 explicit DriveWebAppsRegistry(JobScheduler* scheduler); | 65 explicit DriveAppRegistry(JobScheduler* scheduler); |
64 ~DriveWebAppsRegistry(); | 66 ~DriveAppRegistry(); |
65 | 67 |
66 // Returns a list of web app information for the |file| with |mime_type|. | 68 // Returns a list of web app information for the |file| with |mime_type|. |
67 void GetWebAppsForFile(const base::FilePath& file, | 69 void GetAppsForFile(const base::FilePath& file_path, |
68 const std::string& mime_type, | 70 const std::string& mime_type, |
69 ScopedVector<DriveWebAppInfo>* apps); | 71 ScopedVector<DriveAppInfo>* apps); |
70 | 72 |
71 // Updates this registry by fetching the data from the server. | 73 // Updates this registry by fetching the data from the server. |
72 void Update(); | 74 void Update(); |
73 | 75 |
74 private: | 76 private: |
75 // Defines WebApp application details that are associated with a given | 77 // Defines application details that are associated with a given |
76 // file extension or content mimetype. | 78 // file extension or content mimetype. |
77 struct WebAppFileSelector { | 79 struct DriveAppFileSelector { |
78 WebAppFileSelector( | 80 DriveAppFileSelector( |
79 const GURL& product_link, | 81 const GURL& product_link, |
80 const google_apis::InstalledApp::IconList& app_icons, | 82 const google_apis::InstalledApp::IconList& app_icons, |
81 const google_apis::InstalledApp::IconList& document_icons, | 83 const google_apis::InstalledApp::IconList& document_icons, |
82 const string16& object_type, | 84 const string16& object_type, |
83 const std::string& app_id, | 85 const std::string& app_id, |
84 bool is_primary_selector); | 86 bool is_primary_selector); |
85 ~WebAppFileSelector(); | 87 ~DriveAppFileSelector(); |
86 // WebApp product link. | 88 // Product link to the webstore. |
87 GURL product_link; | 89 GURL product_link; |
88 // Drive application icon URLs for this app, paired with their size (length | 90 // Drive application icon URLs for this app, paired with their size (length |
89 // of a side in pixels). | 91 // of a side in pixels). |
90 google_apis::InstalledApp::IconList app_icons; | 92 google_apis::InstalledApp::IconList app_icons; |
91 // Drive document icon URLs for this app, paired with their size (length of | 93 // Drive document icon URLs for this app, paired with their size (length of |
92 // a side in pixels). | 94 // a side in pixels). |
93 google_apis::InstalledApp::IconList document_icons; | 95 google_apis::InstalledApp::IconList document_icons; |
94 // Object (file) type description. | 96 // Object (file) type description. |
95 string16 object_type; | 97 string16 object_type; |
96 // Drive app id | 98 // Drive app id |
97 std::string app_id; | 99 std::string app_id; |
98 // True if the selector is the default one. The default selector should | 100 // True if the selector is the default one. The default selector should |
99 // trigger on file double-click events. Non-default selectors only show up | 101 // trigger on file double-click events. Non-default selectors only show up |
100 // in "Open with..." pop-up menu. | 102 // in "Open with..." pop-up menu. |
101 bool is_primary_selector; | 103 bool is_primary_selector; |
102 }; | 104 }; |
103 | 105 |
104 // Defines mapping between file content type selectors (extensions, MIME | 106 // Defines mapping between file content type selectors (extensions, MIME |
105 // types) and corresponding WebApp. | 107 // types) and corresponding app. |
106 typedef std::multimap<std::string, WebAppFileSelector*> WebAppFileSelectorMap; | 108 typedef std::multimap<std::string, |
109 DriveAppFileSelector*> DriveAppFileSelectorMap; | |
107 | 110 |
108 // Helper map used for deduplication of selector matching results. | 111 // Helper map used for deduplication of selector matching results. |
109 typedef std::map<const WebAppFileSelector*, | 112 typedef std::map<const DriveAppFileSelector*, |
110 DriveWebAppInfo*> SelectorWebAppList; | 113 DriveAppInfo*> SelectorAppList; |
111 | 114 |
112 // Part of Update(). Runs upon the completion of fetching the web apps | 115 // Part of Update(). Runs upon the completion of fetching the web apps |
113 // data from the server. | 116 // data from the server. |
114 void UpdateAfterGetAppList(google_apis::GDataErrorCode gdata_error, | 117 void UpdateAfterGetAppList(google_apis::GDataErrorCode gdata_error, |
115 scoped_ptr<google_apis::AppList> app_list); | 118 scoped_ptr<google_apis::AppList> app_list); |
116 | 119 |
117 // Helper function for loading web application file |selectors| into | 120 // Helper function for loading web application file |selectors| into |
118 // corresponding |map|. | 121 // corresponding |map|. |
119 static void AddAppSelectorList( | 122 static void AddAppSelectorList( |
120 const GURL& product_link, | 123 const GURL& product_link, |
121 const google_apis::InstalledApp::IconList& app_icons, | 124 const google_apis::InstalledApp::IconList& app_icons, |
122 const google_apis::InstalledApp::IconList& document_icons, | 125 const google_apis::InstalledApp::IconList& document_icons, |
123 const std::string& object_type, | 126 const std::string& object_type, |
124 const std::string& app_id, | 127 const std::string& app_id, |
125 bool is_primary_selector, | 128 bool is_primary_selector, |
126 const ScopedVector<std::string>& selectors, | 129 const ScopedVector<std::string>& selectors, |
127 WebAppFileSelectorMap* map); | 130 DriveAppFileSelectorMap* map); |
128 | 131 |
129 // Finds matching |apps| from |map| based on provided file |selector|. | 132 // Finds matching |apps| from |map| based on provided file |selector|. |
130 void FindWebAppsForSelector(const std::string& selector, | 133 void FindAppsForSelector(const std::string& selector, |
131 const WebAppFileSelectorMap& map, | 134 const DriveAppFileSelectorMap& map, |
132 SelectorWebAppList* apps); | 135 SelectorAppList* apps); |
133 | 136 |
134 JobScheduler* scheduler_; | 137 JobScheduler* scheduler_; |
135 | 138 |
136 // Map of web store product URL to application name. | 139 // Map of web store product URL to application name. |
137 std::map<GURL, std::string> url_to_name_map_; | 140 std::map<GURL, std::string> url_to_name_map_; |
138 | 141 |
139 // Map of filename extension to application info. | 142 // Map of filename extension to application info. |
140 WebAppFileSelectorMap webapp_extension_map_; | 143 DriveAppFileSelectorMap app_extension_map_; |
141 | 144 |
142 // Map of MIME type to application info. | 145 // Map of MIME type to application info. |
143 WebAppFileSelectorMap webapp_mimetypes_map_; | 146 DriveAppFileSelectorMap app_mimetypes_map_; |
144 | 147 |
145 // Note: This should remain the last member so it'll be destroyed and | 148 // Note: This should remain the last member so it'll be destroyed and |
146 // invalidate the weak pointers before any other members are destroyed. | 149 // invalidate the weak pointers before any other members are destroyed. |
147 base::WeakPtrFactory<DriveWebAppsRegistry> weak_ptr_factory_; | 150 base::WeakPtrFactory<DriveAppRegistry> weak_ptr_factory_; |
148 DISALLOW_COPY_AND_ASSIGN(DriveWebAppsRegistry); | 151 DISALLOW_COPY_AND_ASSIGN(DriveAppRegistry); |
149 }; | 152 }; |
150 | 153 |
151 } // namespace drive | 154 } // namespace drive |
152 | 155 |
153 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_WEBAPPS_REGISTRY_H_ | 156 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_APP_REGISTRY_H_ |
OLD | NEW |