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_APP_REGISTRY_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_APP_REGISTRY_H_ |
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_APP_REGISTRY_H_ | 6 #define CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_APP_REGISTRY_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/scoped_vector.h" | |
15 #include "base/memory/weak_ptr.h" | 14 #include "base/memory/weak_ptr.h" |
16 #include "google_apis/drive/gdata_errorcode.h" | 15 #include "google_apis/drive/gdata_errorcode.h" |
17 #include "google_apis/drive/gdata_wapi_parser.h" | 16 #include "google_apis/drive/gdata_wapi_parser.h" |
18 #include "url/gurl.h" | 17 #include "url/gurl.h" |
19 | 18 |
20 namespace google_apis { | 19 namespace google_apis { |
21 class AppList; | 20 class AppList; |
22 } // namespace google_apis | 21 } // namespace google_apis |
23 | 22 |
24 namespace drive { | 23 namespace drive { |
25 | 24 |
26 class JobScheduler; | 25 class DriveServiceInterface; |
27 | 26 |
28 // Data structure that defines Drive app. See | 27 // Data structure that defines Drive app. See |
29 // https://chrome.google.com/webstore/category/collection/drive_apps for | 28 // https://chrome.google.com/webstore/category/collection/drive_apps for |
30 // Drive apps available on the webstore. | 29 // Drive apps available on the webstore. |
31 struct DriveAppInfo { | 30 struct DriveAppInfo { |
32 DriveAppInfo(); | 31 DriveAppInfo(); |
33 DriveAppInfo(const std::string& app_id, | 32 DriveAppInfo(const std::string& app_id, |
34 const google_apis::InstalledApp::IconList& app_icons, | 33 const google_apis::InstalledApp::IconList& app_icons, |
35 const google_apis::InstalledApp::IconList& document_icons, | 34 const google_apis::InstalledApp::IconList& document_icons, |
36 const std::string& app_name, | 35 const std::string& app_name, |
37 const GURL& create_url); | 36 const GURL& create_url); |
38 ~DriveAppInfo(); | 37 ~DriveAppInfo(); |
39 | 38 |
40 // Drive app id. | 39 // Drive app id. |
41 std::string app_id; | 40 std::string app_id; |
42 // Drive application icon URLs for this app, paired with their size (length of | 41 // Drive application icon URLs for this app, paired with their size (length of |
43 // a side in pixels). | 42 // a side in pixels). |
44 google_apis::InstalledApp::IconList app_icons; | 43 google_apis::InstalledApp::IconList app_icons; |
45 // Drive document icon URLs for this app, paired with their size (length of | 44 // Drive document icon URLs for this app, paired with their size (length of |
46 // a side in pixels). | 45 // a side in pixels). |
47 google_apis::InstalledApp::IconList document_icons; | 46 google_apis::InstalledApp::IconList document_icons; |
48 // App name. | 47 // App name. |
49 std::string app_name; | 48 std::string app_name; |
50 // URL for opening a new file in the app. | 49 // URL for opening a new file in the app. Empty if the app does not support |
| 50 // new file creation. |
51 GURL create_url; | 51 GURL create_url; |
52 }; | 52 }; |
53 | 53 |
54 // Keeps the track of installed drive applications in-memory. | 54 // Keeps the track of installed drive applications in-memory. |
55 class DriveAppRegistry { | 55 class DriveAppRegistry { |
56 public: | 56 public: |
57 explicit DriveAppRegistry(JobScheduler* scheduler); | 57 explicit DriveAppRegistry(DriveServiceInterface* scheduler); |
58 ~DriveAppRegistry(); | 58 ~DriveAppRegistry(); |
59 | 59 |
60 // Returns a list of Drive app information for the |file_extension| with | 60 // Returns a list of Drive app information for the |file_extension| with |
61 // |mime_type|. | 61 // |mime_type|. |
62 void GetAppsForFile(const base::FilePath::StringType& file_extension, | 62 void GetAppsForFile(const base::FilePath::StringType& file_extension, |
63 const std::string& mime_type, | 63 const std::string& mime_type, |
64 ScopedVector<DriveAppInfo>* apps) const; | 64 std::vector<DriveAppInfo>* apps) const; |
65 | 65 |
66 // Updates this registry by fetching the data from the server. | 66 // Updates this registry by fetching the data from the server. |
67 void Update(); | 67 void Update(); |
68 | 68 |
69 // Updates this registry from the |app_list|. | 69 // Updates this registry from the |app_list|. |
70 void UpdateFromAppList(const google_apis::AppList& app_list); | 70 void UpdateFromAppList(const google_apis::AppList& app_list); |
71 | 71 |
72 private: | 72 private: |
73 // Part of Update(). Runs upon the completion of fetching the Drive apps | 73 // Part of Update(). Runs upon the completion of fetching the Drive apps |
74 // data from the server. | 74 // data from the server. |
75 void UpdateAfterGetAppList(google_apis::GDataErrorCode gdata_error, | 75 void UpdateAfterGetAppList(google_apis::GDataErrorCode gdata_error, |
76 scoped_ptr<google_apis::AppList> app_list); | 76 scoped_ptr<google_apis::AppList> app_list); |
77 | 77 |
78 // Map of application id to each app's info. | 78 // Map of application id to each app's info. |
79 std::map<std::string, DriveAppInfo> all_apps_; | 79 std::map<std::string, DriveAppInfo> all_apps_; |
80 | 80 |
81 // Defines mapping between file content type selectors (extensions, MIME | 81 // Defines mapping between file content type selectors (extensions, MIME |
82 // types) and corresponding app. | 82 // types) and corresponding app. |
83 typedef std::multimap<std::string, std::string> DriveAppFileSelectorMap; | 83 typedef std::multimap<std::string, std::string> DriveAppFileSelectorMap; |
84 DriveAppFileSelectorMap extension_map_; | 84 DriveAppFileSelectorMap extension_map_; |
85 DriveAppFileSelectorMap mimetype_map_; | 85 DriveAppFileSelectorMap mimetype_map_; |
86 | 86 |
87 JobScheduler* scheduler_; | 87 DriveServiceInterface* drive_service_; |
88 | 88 |
89 bool is_updating_; | 89 bool is_updating_; |
90 | 90 |
91 // Note: This should remain the last member so it'll be destroyed and | 91 // Note: This should remain the last member so it'll be destroyed and |
92 // invalidate the weak pointers before any other members are destroyed. | 92 // invalidate the weak pointers before any other members are destroyed. |
93 base::WeakPtrFactory<DriveAppRegistry> weak_ptr_factory_; | 93 base::WeakPtrFactory<DriveAppRegistry> weak_ptr_factory_; |
94 DISALLOW_COPY_AND_ASSIGN(DriveAppRegistry); | 94 DISALLOW_COPY_AND_ASSIGN(DriveAppRegistry); |
95 }; | 95 }; |
96 | 96 |
97 namespace util { | 97 namespace util { |
98 | 98 |
99 // The preferred icon size, which should usually be used for FindPreferredIcon; | 99 // The preferred icon size, which should usually be used for FindPreferredIcon; |
100 const int kPreferredIconSize = 16; | 100 const int kPreferredIconSize = 16; |
101 | 101 |
102 // Finds an icon in the list of icons. If unable to find an icon of the exact | 102 // Finds an icon in the list of icons. If unable to find an icon of the exact |
103 // size requested, returns one with the next larger size. If all icons are | 103 // size requested, returns one with the next larger size. If all icons are |
104 // smaller than the preferred size, we'll return the largest one available. | 104 // smaller than the preferred size, we'll return the largest one available. |
105 // Icons do not have to be sorted by the icon size. If there are no icons in | 105 // Icons do not have to be sorted by the icon size. If there are no icons in |
106 // the list, returns an empty URL. | 106 // the list, returns an empty URL. |
107 GURL FindPreferredIcon(const google_apis::InstalledApp::IconList& icons, | 107 GURL FindPreferredIcon(const google_apis::InstalledApp::IconList& icons, |
108 int preferred_size); | 108 int preferred_size); |
109 | 109 |
110 } // namespace util | 110 } // namespace util |
111 | 111 |
112 } // namespace drive | 112 } // namespace drive |
113 | 113 |
114 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_APP_REGISTRY_H_ | 114 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_DRIVE_APP_REGISTRY_H_ |
OLD | NEW |