Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/platform_util.h" | 5 #include "chrome/browser/platform_util.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | |
| 7 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 8 #include "base/process_util.h" | 9 #include "base/process_util.h" |
| 9 #include "base/task.h" | 10 #include "base/task.h" |
| 10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/extensions/file_manager_util.h" | 12 #include "chrome/browser/extensions/file_manager_util.h" |
| 12 #include "chrome/browser/tabs/tab_strip_model.h" | 13 #include "chrome/browser/tabs/tab_strip_model.h" |
| 13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 14 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 15 #include "content/common/process_watcher.h" | 16 #include "content/common/process_watcher.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 | 19 |
| 19 using content::BrowserThread; | 20 using content::BrowserThread; |
| 20 | 21 |
| 21 class Profile; | 22 class Profile; |
| 22 | 23 |
| 23 namespace platform_util { | 24 namespace { |
| 24 | 25 |
| 25 static const std::string kGmailComposeUrl = | 26 const std::string kGmailComposeUrl = |
| 26 "https://mail.google.com/mail/?extsrc=mailto&url="; | 27 "https://mail.google.com/mail/?extsrc=mailto&url="; |
| 27 | 28 |
| 29 void OpenItemOnFileThread(const FilePath& full_path) { | |
| 30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | |
| 31 base::Closure callback; | |
| 32 if (file_util::DirectoryExists(full_path)) | |
| 33 callback = base::Bind(&FileManagerUtil::ViewFolder, full_path); | |
| 34 else | |
| 35 callback = base::Bind(&FileManagerUtil::ViewItem, full_path, false); | |
| 36 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); | |
| 37 } | |
| 38 | |
| 28 // Opens file browser on UI thread. | 39 // Opens file browser on UI thread. |
| 29 static | |
| 30 void OpenFileBrowserOnUIThread(const FilePath& dir) { | 40 void OpenFileBrowserOnUIThread(const FilePath& dir) { |
| 31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 32 | 42 |
| 33 Browser* browser = BrowserList::GetLastActive(); | 43 Browser* browser = BrowserList::GetLastActive(); |
| 34 if (!browser) | 44 if (!browser) |
| 35 return; | 45 return; |
| 36 | 46 |
| 37 FilePath virtual_path; | 47 FilePath virtual_path; |
| 38 if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath(browser->profile(), | 48 if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath(browser->profile(), |
| 39 dir, | 49 dir, |
| 40 &virtual_path)) { | 50 &virtual_path)) { |
| 41 return; | 51 return; |
| 42 } | 52 } |
| 43 | 53 |
| 44 GURL url = FileManagerUtil::GetFileBrowserUrlWithParams( | 54 GURL url = FileManagerUtil::GetFileBrowserUrlWithParams( |
| 45 SelectFileDialog::SELECT_NONE, string16(), virtual_path, NULL, 0, | 55 SelectFileDialog::SELECT_NONE, string16(), virtual_path, NULL, 0, |
| 46 FilePath::StringType()); | 56 FilePath::StringType()); |
| 47 browser->ShowSingletonTab(url); | 57 browser->ShowSingletonTab(url); |
| 48 } | 58 } |
| 49 | 59 |
| 60 void OpenURL(const std::string& url) { | |
| 61 Browser* browser = BrowserList::GetLastActive(); | |
| 62 browser->AddSelectedTabWithURL(GURL(url), content::PAGE_TRANSITION_LINK); | |
| 63 } | |
| 64 | |
| 65 } // namespace | |
| 66 | |
| 67 namespace platform_util { | |
| 68 | |
| 50 void ShowItemInFolder(const FilePath& full_path) { | 69 void ShowItemInFolder(const FilePath& full_path) { |
| 51 FilePath dir = full_path.DirName(); | 70 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| 52 if (!file_util::DirectoryExists(dir)) | 71 FilePath dir = full_path.DirName(); |
| 53 return; | 72 if (!file_util::DirectoryExists(dir)) |
| 73 return; | |
| 54 | 74 |
| 55 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { | 75 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 56 OpenFileBrowserOnUIThread(dir); | 76 base::Bind(&OpenFileBrowserOnUIThread, dir)); |
| 57 } else { | 77 } else { |
| 58 BrowserThread::PostTask( | 78 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 59 BrowserThread::UI, FROM_HERE, | 79 base::Bind(&ShowItemInFolder, full_path)); |
|
Randy Smith (Not in Mondays)
2011/11/09 17:20:30
nit, suggestion (i.e. up to you if you want to tak
achuithb
2011/11/09 20:21:36
I had your suggestion in this CL and then switched
| |
| 60 NewRunnableFunction(&OpenFileBrowserOnUIThread, dir)); | |
| 61 } | 80 } |
| 62 } | 81 } |
| 63 | 82 |
| 64 void OpenItem(const FilePath& full_path) { | 83 void OpenItem(const FilePath& full_path) { |
| 65 FileManagerUtil::ViewItem(full_path, false); | 84 if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) |
| 66 } | 85 OpenItemOnFileThread(full_path); |
| 67 | 86 else |
| 68 static void OpenURL(const std::string& url) { | 87 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
|
Mark Mentovai
2011/11/09 14:22:50
What’s the point of this if you ultimately need th
achuithb
2011/11/09 20:21:36
file_util::DirectoryExists must be called on the F
| |
| 69 Browser* browser = BrowserList::GetLastActive(); | 88 base::Bind(&OpenItemOnFileThread, full_path)); |
| 70 browser->AddSelectedTabWithURL(GURL(url), content::PAGE_TRANSITION_LINK); | |
| 71 } | 89 } |
| 72 | 90 |
| 73 void OpenExternal(const GURL& url) { | 91 void OpenExternal(const GURL& url) { |
| 74 if (url.SchemeIs("mailto")) { | 92 if (url.SchemeIs("mailto")) { |
| 75 std::string string_url = kGmailComposeUrl; | 93 std::string string_url = kGmailComposeUrl; |
| 76 string_url.append(url.spec()); | 94 string_url.append(url.spec()); |
| 77 BrowserThread::PostTask( | 95 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 78 BrowserThread::UI, FROM_HERE, NewRunnableFunction(OpenURL, string_url)); | 96 base::Bind(OpenURL, string_url)); |
| 79 } | 97 } |
| 80 } | 98 } |
| 81 | 99 |
| 82 } // namespace platform_util | 100 } // namespace platform_util |
| OLD | NEW |