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

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

Powered by Google App Engine
This is Rietveld 408576698