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