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

Side by Side Diff: chrome/browser/chromeos/extensions/file_handler_util.h

Issue 10834383: Chrome OS "open with" picker allowing Web Intents (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: tbarzic comments Created 8 years, 3 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 (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_EXTENSIONS_FILE_HANDLER_UTIL_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_
6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ 6 #define CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_
7 7
8 #include <string>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/callback.h" 11 #include "base/callback.h"
11 #include "base/platform_file.h" 12 #include "base/platform_file.h"
12 #include "chrome/common/extensions/extension.h" 13 #include "chrome/common/extensions/extension.h"
13 #include "chrome/common/extensions/file_browser_handler.h" 14 #include "chrome/common/extensions/file_browser_handler.h"
14 #include "chrome/common/extensions/url_pattern_set.h" 15 #include "chrome/common/extensions/url_pattern_set.h"
15 16
16 class Browser; 17 class Browser;
17 class GURL; 18 class GURL;
18 class Profile; 19 class Profile;
19 20
21 namespace extensions {
22 class Extension;
23 } // namespace extensions
24
20 namespace file_handler_util { 25 namespace file_handler_util {
21 26
27 // Specifies the task type for a task id that represents some file action, Drive
28 // action, or Web Intent action.
29 extern const char kTaskFile[];
30 extern const char kTaskDrive[];
31 extern const char kTaskWebIntent[];
32
33 void UpdateFileHandlerUsageStats(Profile* profile, const std::string& task_id);
34
22 // Update the default file handler for the given sets of suffixes and MIME 35 // Update the default file handler for the given sets of suffixes and MIME
23 // types. 36 // types.
24 void UpdateDefaultTask(Profile* profile, 37 void UpdateDefaultTask(Profile* profile,
25 const std::string& task_id, 38 const std::string& task_id,
26 const std::set<std::string>& suffixes, 39 const std::set<std::string>& suffixes,
27 const std::set<std::string>& mime_types); 40 const std::set<std::string>& mime_types);
28 41
29 // Returns the task ID of the default task for the given |mime_type|/|suffix| 42 // Returns the task ID of the default task for the given |mime_type|/|suffix|
30 // combination. If it finds a MIME type match, then it prefers that over a 43 // combination. If it finds a MIME type match, then it prefers that over a
31 // suffix match. If it a default can't be found, then it returns the empty 44 // suffix match. If it a default can't be found, then it returns the empty
32 // string. 45 // string.
33 std::string GetDefaultTaskIdFromPrefs(Profile* profile, 46 std::string GetDefaultTaskIdFromPrefs(Profile* profile,
34 const std::string& mime_type, 47 const std::string& mime_type,
35 const std::string& suffix); 48 const std::string& suffix);
36 49
37 // Gets read-write file access permission flags. 50 // Gets read-write file access permission flags.
38 int GetReadWritePermissions(); 51 int GetReadWritePermissions();
39 // Gets read-only file access permission flags. 52 // Gets read-only file access permission flags.
40 int GetReadOnlyPermissions(); 53 int GetReadOnlyPermissions();
41 54
42 // Generates file task id for the file action specified by the extension. 55 // Generates task id for the action specified by the extension. The |task_type|
56 // must be one of kTaskFile, kTaskDrive, or kTaskWebIntent.
43 std::string MakeTaskID(const std::string& extension_id, 57 std::string MakeTaskID(const std::string& extension_id,
58 const std::string& task_type,
44 const std::string& action_id); 59 const std::string& action_id);
45 60
46 // Make a task id specific to drive apps instead of extensions. 61 // Extracts action, type and extension id bound to the file task. Either
47 std::string MakeDriveTaskID(const std::string& app_id,
48 const std::string& action_id);
49
50 // Returns the |target_id| and |action_id| of a drive app or extension, given
51 // the drive |task_id| created by MakeDriveTaskID. If the |task_id| is a drive
52 // task_id then it will return true. If not, or if parsing fails, will return
53 // false and not set |app_id| or |action_id|.
54 bool CrackDriveTaskID(const std::string& task_id,
55 std::string* app_id,
56 std::string* action_id);
57
58 // Extracts action and extension id bound to the file task. Either
59 // |target_extension_id| or |action_id| are allowed to be NULL if caller isn't 62 // |target_extension_id| or |action_id| are allowed to be NULL if caller isn't
60 // interested in those values. Returns false on failure to parse. 63 // interested in those values. Returns false on failure to parse.
61 bool CrackTaskID(const std::string& task_id, 64 bool CrackTaskID(const std::string& task_id,
62 std::string* target_extension_id, 65 std::string* target_extension_id,
66 std::string* task_type,
63 std::string* action_id); 67 std::string* action_id);
64 68
65 // This generates a list of default tasks (tasks set as default by the user in 69 // This generates a list of default tasks (tasks set as default by the user in
66 // prefs) from the |common_tasks|. 70 // prefs) from the |common_tasks|.
67 void FindDefaultTasks(Profile* profile, 71 void FindDefaultTasks(Profile* profile,
68 const std::vector<GURL>& files_list, 72 const std::vector<GURL>& files_list,
69 const std::set<const FileBrowserHandler*>& common_tasks, 73 const std::set<const FileBrowserHandler*>& common_tasks,
70 std::set<const FileBrowserHandler*>* default_tasks); 74 std::set<const FileBrowserHandler*>* default_tasks);
71 75
72 // This generates list of tasks common for all files in |file_list|. 76 // This generates list of tasks common for all files in |file_list|.
73 bool FindCommonTasks(Profile* profile, 77 bool FindCommonTasks(Profile* profile,
74 const std::vector<GURL>& files_list, 78 const std::vector<GURL>& files_list,
75 std::set<const FileBrowserHandler*>* common_tasks); 79 std::set<const FileBrowserHandler*>* common_tasks);
76 80
77 // Finds a task for a file whose URL is |url|. 81 // Finds a task for a file whose URL is |url|.
78 // Returns default task if one is defined (The default task is the task that is 82 // Returns default task if one is defined (The default task is the task that is
79 // assigned to file browser task button by default). If default task is not 83 // assigned to file browser task button by default). If default task is not
80 // found, tries to match the url with one of the builtin tasks. 84 // found, tries to match the url with one of the builtin tasks.
81 bool GetTaskForURL(Profile* profile, 85 bool GetTaskForURL(Profile* profile,
82 const GURL& url, 86 const GURL& url,
83 const FileBrowserHandler** handler); 87 const FileBrowserHandler** handler);
84 88
85 // Used for returning success or failure from task executions. 89 // Used for returning success or failure from task executions.
86 typedef base::Callback<void(bool)> FileTaskFinishedCallback; 90 typedef base::Callback<void(bool)> FileTaskFinishedCallback;
87 91
88 // Helper class for executing file browser file action. 92 // Helper class for executing file browser file action.
89 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> { 93 class FileTaskExecutor : public base::RefCountedThreadSafe<FileTaskExecutor> {
90 public: 94 public:
91 static const char kDriveTaskExtensionPrefix[];
92 static const size_t kDriveTaskExtensionPrefixLength;
93
94 // Creates the appropriate FileTaskExecutor for the given |extension_id|. 95 // Creates the appropriate FileTaskExecutor for the given |extension_id|.
95 static FileTaskExecutor* Create(Profile* profile, 96 static FileTaskExecutor* Create(Profile* profile,
96 const GURL source_url, 97 const GURL source_url,
97 const std::string& extension_id, 98 const std::string& extension_id,
99 const std::string& task_type,
98 const std::string& action_id); 100 const std::string& action_id);
99 101
100 // Same as ExecuteAndNotify, but no notification is performed. 102 // Same as ExecuteAndNotify, but no notification is performed.
101 virtual bool Execute(const std::vector<GURL>& file_urls); 103 virtual bool Execute(const std::vector<GURL>& file_urls);
102 104
103 // Initiates execution of file handler task for each element of |file_urls|. 105 // Initiates execution of file handler task for each element of |file_urls|.
104 // Return |false| if the execution cannot be initiated. Otherwise returns 106 // Return |false| if the execution cannot be initiated. Otherwise returns
105 // |true| and then eventually calls |done| when all the files have 107 // |true| and then eventually calls |done| when all the files have
106 // been handled. If there is an error during processing the list of files, the 108 // been handled. If there is an error during processing the list of files, the
107 // caller will be informed of the failure via |done|, and the rest of 109 // caller will be informed of the failure via |done|, and the rest of
108 // the files will not be processed. 110 // the files will not be processed.
109 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls, 111 virtual bool ExecuteAndNotify(const std::vector<GURL>& file_urls,
110 const FileTaskFinishedCallback& done) = 0; 112 const FileTaskFinishedCallback& done) = 0;
111 113
112 protected: 114 protected:
113 explicit FileTaskExecutor(Profile* profile); 115 explicit FileTaskExecutor(Profile* profile, const std::string& extension_id);
114 virtual ~FileTaskExecutor(); 116 virtual ~FileTaskExecutor();
115 117
116 // Returns the profile that this task was created with. 118 // Returns the profile that this task was created with.
117 Profile* profile() { return profile_; } 119 Profile* profile() { return profile_; }
118 120
119 // Returns a browser to use for the current browser. 121 // Returns a browser to use for the current browser.
120 Browser* GetBrowser() const; 122 Browser* GetBrowser() const;
123
124 // Returns the extension for this profile.
125 const extensions::Extension* GetExtension();
126
127 // Returns the extension ID set for this FileTaskExecutor.
128 const std::string& extension_id() { return extension_id_; }
129
121 private: 130 private:
122 friend class base::RefCountedThreadSafe<FileTaskExecutor>; 131 friend class base::RefCountedThreadSafe<FileTaskExecutor>;
123 132
124 Profile* profile_; 133 Profile* profile_;
134 const std::string extension_id_;
125 }; 135 };
126 136
127 } // namespace file_handler_util 137 } // namespace file_handler_util
128 138
129 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_ 139 #endif // CHROME_BROWSER_CHROMEOS_EXTENSIONS_FILE_HANDLER_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698