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_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_ | 5 #ifndef CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_ |
6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_ | 6 #define CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_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/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/string16.h" | |
16 | 17 |
17 class Profile; | 18 class Profile; |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class FilePath; | 21 class FilePath; |
21 } | 22 } |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 class WebContents; | 25 class WebContents; |
25 } | 26 } |
(...skipping 12 matching lines...) Expand all Loading... | |
38 }; | 39 }; |
39 | 40 |
40 DevToolsFileHelper(content::WebContents* web_contents, Profile* profile); | 41 DevToolsFileHelper(content::WebContents* web_contents, Profile* profile); |
41 ~DevToolsFileHelper(); | 42 ~DevToolsFileHelper(); |
42 | 43 |
43 typedef base::Callback<void(void)> SaveCallback; | 44 typedef base::Callback<void(void)> SaveCallback; |
44 typedef base::Callback<void(void)> AppendCallback; | 45 typedef base::Callback<void(void)> AppendCallback; |
45 typedef base::Callback< | 46 typedef base::Callback< |
46 void(const std::vector<DevToolsFileHelper::FileSystem>&)> | 47 void(const std::vector<DevToolsFileHelper::FileSystem>&)> |
47 RequestFileSystemsCallback; | 48 RequestFileSystemsCallback; |
48 typedef base::Callback< | 49 typedef base::Callback<void(const DevToolsFileHelper::FileSystem&)> |
49 void(std::string, const DevToolsFileHelper::FileSystem&)> | |
50 AddFileSystemCallback; | 50 AddFileSystemCallback; |
51 typedef base::Callback<void(const string16&, | |
52 const base::Callback<void()>&, | |
pfeldman
2013/04/25 11:06:01
you could name them for convenience.
| |
53 const base::Callback<void()>&)> | |
54 ShowInfoBarCallback; | |
51 | 55 |
52 // Saves |content| to the file and associates its path with given |url|. | 56 // Saves |content| to the file and associates its path with given |url|. |
53 // If client is calling this method with given |url| for the first time | 57 // If client is calling this method with given |url| for the first time |
54 // or |save_as| is true, confirmation dialog is shown to the user. | 58 // or |save_as| is true, confirmation dialog is shown to the user. |
55 void Save(const std::string& url, | 59 void Save(const std::string& url, |
56 const std::string& content, | 60 const std::string& content, |
57 bool save_as, | 61 bool save_as, |
58 const SaveCallback& callback); | 62 const SaveCallback& callback); |
59 | 63 |
60 // Append |content| to the file that has been associated with given |url|. | 64 // Append |content| to the file that has been associated with given |url|. |
61 // The |url| can be associated with a file via calling Save method. | 65 // The |url| can be associated with a file via calling Save method. |
62 // If the Save method has not been called for this |url|, then | 66 // If the Save method has not been called for this |url|, then |
63 // Append method does nothing. | 67 // Append method does nothing. |
64 void Append(const std::string& url, | 68 void Append(const std::string& url, |
65 const std::string& content, | 69 const std::string& content, |
66 const AppendCallback& callback); | 70 const AppendCallback& callback); |
67 | 71 |
68 // Shows select folder dialog. | 72 // Shows select folder dialog. |
69 // If user cancels folder selection, passes empty FileSystem struct to | 73 // If user cancels folder selection, passes empty FileSystem struct to |
70 // |callback|. | 74 // |callback|. |
71 // If selected folder contains magic file, grants renderer read/write | 75 // If selected folder contains magic file, grants renderer read/write |
72 // permissions, registers isolated file system for it and passes FileSystem | 76 // permissions, registers isolated file system for it and passes FileSystem |
73 // struct to |callback|. Saves file system path to prefs. | 77 // struct to |callback|. Saves file system path to prefs. |
74 // If selected folder does not contain magic file, passes error string to | 78 // If selected folder does not contain magic file, passes error string to |
75 // |callback|. | 79 // |callback|. |
76 void AddFileSystem(const AddFileSystemCallback& callback); | 80 void AddFileSystem(const AddFileSystemCallback& callback, |
81 const ShowInfoBarCallback& show_info_bar_callback); | |
77 | 82 |
78 // Loads file system paths from prefs, grants permissions and registers | 83 // Loads file system paths from prefs, grants permissions and registers |
79 // isolated file system for those of them that contain magic file and passes | 84 // isolated file system for those of them that contain magic file and passes |
80 // FileSystem structs for registered file systems to |callback|. | 85 // FileSystem structs for registered file systems to |callback|. |
81 void RequestFileSystems(const RequestFileSystemsCallback& callback); | 86 void RequestFileSystems(const RequestFileSystemsCallback& callback); |
82 | 87 |
83 // Removes isolated file system for given |file_system_path|. | 88 // Removes isolated file system for given |file_system_path|. |
84 void RemoveFileSystem(const std::string& file_system_path); | 89 void RemoveFileSystem(const std::string& file_system_path); |
85 | 90 |
86 private: | 91 private: |
87 void SaveAsFileSelected(const std::string& url, | 92 void SaveAsFileSelected(const std::string& url, |
88 const std::string& content, | 93 const std::string& content, |
89 const SaveCallback& callback, | 94 const SaveCallback& callback, |
90 const base::FilePath& path); | 95 const base::FilePath& path); |
91 void SaveAsFileSelectionCanceled(); | 96 void SaveAsFileSelectionCanceled(); |
92 void InnerAddFileSystem(const AddFileSystemCallback& callback, | 97 void InnerAddFileSystem( |
93 const base::FilePath& path); | |
94 void AddValidatedFileSystem( | |
95 const AddFileSystemCallback& callback, | 98 const AddFileSystemCallback& callback, |
96 const std::vector<base::FilePath>& permitted_paths); | 99 const ShowInfoBarCallback& show_info_bar_callback, |
100 const base::FilePath& path); | |
101 void AddUserConfirmedFileSystem( | |
102 const AddFileSystemCallback& callback, | |
103 const base::FilePath& path); | |
97 void RestoreValidatedFileSystems( | 104 void RestoreValidatedFileSystems( |
98 const RequestFileSystemsCallback& callback, | 105 const RequestFileSystemsCallback& callback, |
99 const std::vector<base::FilePath>& file_paths); | 106 const std::vector<base::FilePath>& file_paths); |
100 | 107 |
101 content::WebContents* web_contents_; | 108 content::WebContents* web_contents_; |
102 Profile* profile_; | 109 Profile* profile_; |
103 base::WeakPtrFactory<DevToolsFileHelper> weak_factory_; | 110 base::WeakPtrFactory<DevToolsFileHelper> weak_factory_; |
104 typedef std::map<std::string, base::FilePath> PathsMap; | 111 typedef std::map<std::string, base::FilePath> PathsMap; |
105 PathsMap saved_files_; | 112 PathsMap saved_files_; |
106 DISALLOW_COPY_AND_ASSIGN(DevToolsFileHelper); | 113 DISALLOW_COPY_AND_ASSIGN(DevToolsFileHelper); |
107 }; | 114 }; |
108 | 115 |
109 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_ | 116 #endif // CHROME_BROWSER_DEVTOOLS_DEVTOOLS_FILE_HELPER_H_ |
OLD | NEW |