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 #include "chrome/browser/devtools/devtools_file_helper.h" | 5 #include "chrome/browser/devtools/devtools_file_helper.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/md5.h" | 14 #include "base/md5.h" |
15 #include "base/prefs/pref_service.h" | 15 #include "base/prefs/pref_service.h" |
16 #include "base/prefs/scoped_user_pref_update.h" | 16 #include "base/prefs/scoped_user_pref_update.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/value_conversions.h" | 18 #include "base/value_conversions.h" |
19 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 20 #include "chrome/browser/devtools/devtools_file_watcher.h" |
20 #include "chrome/browser/download/download_prefs.h" | 21 #include "chrome/browser/download/download_prefs.h" |
21 #include "chrome/browser/platform_util.h" | 22 #include "chrome/browser/platform_util.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/ui/chrome_select_file_policy.h" | 24 #include "chrome/browser/ui/chrome_select_file_policy.h" |
24 #include "chrome/common/pref_names.h" | 25 #include "chrome/common/pref_names.h" |
25 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
26 #include "content/public/browser/browser_context.h" | 27 #include "content/public/browser/browser_context.h" |
27 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
28 #include "content/public/browser/child_process_security_policy.h" | 29 #include "content/public/browser/child_process_security_policy.h" |
29 #include "content/public/browser/download_manager.h" | 30 #include "content/public/browser/download_manager.h" |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 Profile* profile, | 206 Profile* profile, |
206 Delegate* delegate) | 207 Delegate* delegate) |
207 : web_contents_(web_contents), | 208 : web_contents_(web_contents), |
208 profile_(profile), | 209 profile_(profile), |
209 delegate_(delegate), | 210 delegate_(delegate), |
210 weak_factory_(this) { | 211 weak_factory_(this) { |
211 pref_change_registrar_.Init(profile_->GetPrefs()); | 212 pref_change_registrar_.Init(profile_->GetPrefs()); |
212 pref_change_registrar_.Add(prefs::kDevToolsFileSystemPaths, | 213 pref_change_registrar_.Add(prefs::kDevToolsFileSystemPaths, |
213 base::Bind(&DevToolsFileHelper::FileSystemPathsSettingChanged, | 214 base::Bind(&DevToolsFileHelper::FileSystemPathsSettingChanged, |
214 base::Unretained(this))); | 215 base::Unretained(this))); |
| 216 file_watcher_.reset(new DevToolsFileWatcher( |
| 217 base::Bind(&DevToolsFileHelper::FilePathsChanged, |
| 218 weak_factory_.GetWeakPtr()))); |
215 } | 219 } |
216 | 220 |
217 DevToolsFileHelper::~DevToolsFileHelper() { | 221 DevToolsFileHelper::~DevToolsFileHelper() { |
| 222 BrowserThread::DeleteSoon(BrowserThread::FILE, FROM_HERE, |
| 223 file_watcher_.release()); |
218 } | 224 } |
219 | 225 |
220 void DevToolsFileHelper::Save(const std::string& url, | 226 void DevToolsFileHelper::Save(const std::string& url, |
221 const std::string& content, | 227 const std::string& content, |
222 bool save_as, | 228 bool save_as, |
223 const SaveCallback& saveCallback, | 229 const SaveCallback& saveCallback, |
224 const SaveCallback& cancelCallback) { | 230 const SaveCallback& cancelCallback) { |
225 PathsMap::iterator it = saved_files_.find(url); | 231 PathsMap::iterator it = saved_files_.find(url); |
226 if (it != saved_files_.end() && !save_as) { | 232 if (it != saved_files_.end() && !save_as) { |
227 SaveAsFileSelected(url, content, saveCallback, it->second); | 233 SaveAsFileSelected(url, content, saveCallback, it->second); |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 DevToolsFileHelper::GetFileSystems() { | 391 DevToolsFileHelper::GetFileSystems() { |
386 file_system_paths_ = GetAddedFileSystemPaths(profile_); | 392 file_system_paths_ = GetAddedFileSystemPaths(profile_); |
387 std::vector<FileSystem> file_systems; | 393 std::vector<FileSystem> file_systems; |
388 for (auto file_system_path : file_system_paths_) { | 394 for (auto file_system_path : file_system_paths_) { |
389 base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); | 395 base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); |
390 std::string file_system_id = RegisterFileSystem(web_contents_, path); | 396 std::string file_system_id = RegisterFileSystem(web_contents_, path); |
391 FileSystem filesystem = CreateFileSystemStruct(web_contents_, | 397 FileSystem filesystem = CreateFileSystemStruct(web_contents_, |
392 file_system_id, | 398 file_system_id, |
393 file_system_path); | 399 file_system_path); |
394 file_systems.push_back(filesystem); | 400 file_systems.push_back(filesystem); |
| 401 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 402 Bind(&DevToolsFileWatcher::AddWatch, |
| 403 base::Unretained(file_watcher_.get()), path)); |
395 } | 404 } |
396 return file_systems; | 405 return file_systems; |
397 } | 406 } |
398 | 407 |
399 void DevToolsFileHelper::RemoveFileSystem(const std::string& file_system_path) { | 408 void DevToolsFileHelper::RemoveFileSystem(const std::string& file_system_path) { |
400 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 409 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
401 base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); | 410 base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); |
402 isolated_context()->RevokeFileSystemByPath(path); | 411 isolated_context()->RevokeFileSystemByPath(path); |
403 | 412 |
404 DictionaryPrefUpdate update(profile_->GetPrefs(), | 413 DictionaryPrefUpdate update(profile_->GetPrefs(), |
(...skipping 14 matching lines...) Expand all Loading... |
419 remaining.swap(file_system_paths_); | 428 remaining.swap(file_system_paths_); |
420 | 429 |
421 for (auto file_system_path : GetAddedFileSystemPaths(profile_)) { | 430 for (auto file_system_path : GetAddedFileSystemPaths(profile_)) { |
422 if (remaining.find(file_system_path) == remaining.end()) { | 431 if (remaining.find(file_system_path) == remaining.end()) { |
423 base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); | 432 base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); |
424 std::string file_system_id = RegisterFileSystem(web_contents_, path); | 433 std::string file_system_id = RegisterFileSystem(web_contents_, path); |
425 FileSystem filesystem = CreateFileSystemStruct(web_contents_, | 434 FileSystem filesystem = CreateFileSystemStruct(web_contents_, |
426 file_system_id, | 435 file_system_id, |
427 file_system_path); | 436 file_system_path); |
428 delegate_->FileSystemAdded(filesystem); | 437 delegate_->FileSystemAdded(filesystem); |
| 438 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 439 Bind(&DevToolsFileWatcher::AddWatch, |
| 440 base::Unretained(file_watcher_.get()), |
| 441 path)); |
429 } else { | 442 } else { |
430 remaining.erase(file_system_path); | 443 remaining.erase(file_system_path); |
431 } | 444 } |
432 file_system_paths_.insert(file_system_path); | 445 file_system_paths_.insert(file_system_path); |
433 } | 446 } |
434 | 447 |
435 for (auto file_system_path : remaining) | 448 for (auto file_system_path : remaining) { |
436 delegate_->FileSystemRemoved(file_system_path); | 449 delegate_->FileSystemRemoved(file_system_path); |
| 450 base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); |
| 451 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 452 Bind(&DevToolsFileWatcher::RemoveWatch, |
| 453 base::Unretained(file_watcher_.get()), path)); |
| 454 } |
437 } | 455 } |
| 456 |
| 457 void DevToolsFileHelper::FilePathsChanged( |
| 458 const std::vector<std::string>& paths) { |
| 459 delegate_->FilePathsChanged(paths); |
| 460 } |
OLD | NEW |