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