Chromium Code Reviews| Index: chrome/browser/platform_util_chromeos.cc |
| =================================================================== |
| --- chrome/browser/platform_util_chromeos.cc (revision 108954) |
| +++ chrome/browser/platform_util_chromeos.cc (working copy) |
| @@ -4,6 +4,7 @@ |
| #include "chrome/browser/platform_util.h" |
| +#include "base/bind.h" |
| #include "base/file_util.h" |
| #include "base/process_util.h" |
| #include "base/task.h" |
| @@ -20,13 +21,22 @@ |
| class Profile; |
| -namespace platform_util { |
| +namespace { |
| -static const std::string kGmailComposeUrl = |
| +const std::string kGmailComposeUrl = |
| "https://mail.google.com/mail/?extsrc=mailto&url="; |
| +void OpenItemOnFileThread(const FilePath& full_path) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| + base::Closure callback; |
| + if (file_util::DirectoryExists(full_path)) |
| + callback = base::Bind(&FileManagerUtil::ViewFolder, full_path); |
| + else |
| + callback = base::Bind(&FileManagerUtil::ViewItem, full_path, false); |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback); |
| +} |
| + |
| // Opens file browser on UI thread. |
| -static |
| void OpenFileBrowserOnUIThread(const FilePath& dir) { |
| DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| @@ -47,35 +57,43 @@ |
| browser->ShowSingletonTab(url); |
| } |
| +void OpenURL(const std::string& url) { |
| + Browser* browser = BrowserList::GetLastActive(); |
| + browser->AddSelectedTabWithURL(GURL(url), content::PAGE_TRANSITION_LINK); |
| +} |
| + |
| +} // namespace |
| + |
| +namespace platform_util { |
| + |
| void ShowItemInFolder(const FilePath& full_path) { |
| - FilePath dir = full_path.DirName(); |
| - if (!file_util::DirectoryExists(dir)) |
| - return; |
| + if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) { |
| + FilePath dir = full_path.DirName(); |
| + if (!file_util::DirectoryExists(dir)) |
| + return; |
| - if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { |
| - OpenFileBrowserOnUIThread(dir); |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(&OpenFileBrowserOnUIThread, dir)); |
| } else { |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, |
| - NewRunnableFunction(&OpenFileBrowserOnUIThread, dir)); |
| + BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| + 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
|
| } |
| } |
| void OpenItem(const FilePath& full_path) { |
| - FileManagerUtil::ViewItem(full_path, false); |
| + if (BrowserThread::CurrentlyOn(BrowserThread::FILE)) |
| + OpenItemOnFileThread(full_path); |
| + else |
| + 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
|
| + base::Bind(&OpenItemOnFileThread, full_path)); |
| } |
| -static void OpenURL(const std::string& url) { |
| - Browser* browser = BrowserList::GetLastActive(); |
| - browser->AddSelectedTabWithURL(GURL(url), content::PAGE_TRANSITION_LINK); |
| -} |
| - |
| void OpenExternal(const GURL& url) { |
| if (url.SchemeIs("mailto")) { |
| std::string string_url = kGmailComposeUrl; |
| string_url.append(url.spec()); |
| - BrowserThread::PostTask( |
| - BrowserThread::UI, FROM_HERE, NewRunnableFunction(OpenURL, string_url)); |
| + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| + base::Bind(OpenURL, string_url)); |
| } |
| } |