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

Side by Side Diff: chrome/browser/platform_util_chromeos.cc

Issue 8457004: platform_util::OpenItem fixes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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
24 namespace {
25
26 void OpenItemOnFileThread(const FilePath& full_path) {
27 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
28 base::Closure callback;
29 if (file_util::DirectoryExists(full_path))
30 callback = base::Bind(&FileManagerUtil::ViewFolder, full_path);
31 else
32 callback = base::Bind(&FileManagerUtil::ViewItem, full_path, false);
33 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, callback);
34 }
35
36 } // namespace
37
23 namespace platform_util { 38 namespace platform_util {
24 39
25 static const std::string kGmailComposeUrl = 40 static const std::string kGmailComposeUrl =
26 "https://mail.google.com/mail/?extsrc=mailto&url="; 41 "https://mail.google.com/mail/?extsrc=mailto&url=";
27 42
28 // Opens file browser on UI thread. 43 // Opens file browser on UI thread.
29 static 44 static
30 void OpenFileBrowserOnUIThread(const FilePath& dir) { 45 void OpenFileBrowserOnUIThread(const FilePath& dir) {
31 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 46 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
32 47
33 Browser* browser = BrowserList::GetLastActive(); 48 Browser* browser = BrowserList::GetLastActive();
34 if (!browser) 49 if (!browser)
35 return; 50 return;
36 51
37 FilePath virtual_path; 52 FilePath virtual_path;
38 if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath(browser->profile(), 53 if (!FileManagerUtil::ConvertFileToRelativeFileSystemPath(browser->profile(),
39 dir, 54 dir,
40 &virtual_path)) { 55 &virtual_path)) {
41 return; 56 return;
42 } 57 }
43 58
44 GURL url = FileManagerUtil::GetFileBrowserUrlWithParams( 59 GURL url = FileManagerUtil::GetFileBrowserUrlWithParams(
45 SelectFileDialog::SELECT_NONE, string16(), virtual_path, NULL, 0, 60 SelectFileDialog::SELECT_NONE, string16(), virtual_path, NULL, 0,
46 FilePath::StringType()); 61 FilePath::StringType());
47 browser->ShowSingletonTab(url); 62 browser->ShowSingletonTab(url);
48 } 63 }
49 64
50 void ShowItemInFolder(const FilePath& full_path) { 65 void ShowItemInFolder(const FilePath& full_path) {
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
51 FilePath dir = full_path.DirName(); 67 FilePath dir = full_path.DirName();
52 if (!file_util::DirectoryExists(dir)) 68 if (!file_util::DirectoryExists(dir))
53 return; 69 return;
54 70
55 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) { 71 if (BrowserThread::CurrentlyOn(BrowserThread::UI)) {
56 OpenFileBrowserOnUIThread(dir); 72 OpenFileBrowserOnUIThread(dir);
57 } else { 73 } else {
58 BrowserThread::PostTask( 74 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
59 BrowserThread::UI, FROM_HERE, 75 base::Bind(&OpenFileBrowserOnUIThread, dir));
60 NewRunnableFunction(&OpenFileBrowserOnUIThread, dir));
61 } 76 }
62 } 77 }
63 78
64 void OpenItem(const FilePath& full_path) { 79 void OpenItem(const FilePath& full_path) {
65 FileManagerUtil::ViewItem(full_path, false); 80 if (BrowserThread::CurrentlyOn(BrowserThread::FILE))
81 OpenItemOnFileThread(full_path);
82 else
83 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
84 base::Bind(&OpenItemOnFileThread, full_path));
asanka 2011/11/08 15:29:29 Would it make sense to have an OpenItemOnUIThread(
achuithb 2011/11/08 20:49:57 file_util::DirectoryExists needs to be called on t
asanka 2011/11/08 20:59:33 You're correct. Sorry.
66 } 85 }
67 86
68 static void OpenURL(const std::string& url) { 87 static void OpenURL(const std::string& url) {
69 Browser* browser = BrowserList::GetLastActive(); 88 Browser* browser = BrowserList::GetLastActive();
70 browser->AddSelectedTabWithURL(GURL(url), content::PAGE_TRANSITION_LINK); 89 browser->AddSelectedTabWithURL(GURL(url), content::PAGE_TRANSITION_LINK);
71 } 90 }
72 91
73 void OpenExternal(const GURL& url) { 92 void OpenExternal(const GURL& url) {
74 if (url.SchemeIs("mailto")) { 93 if (url.SchemeIs("mailto")) {
75 std::string string_url = kGmailComposeUrl; 94 std::string string_url = kGmailComposeUrl;
76 string_url.append(url.spec()); 95 string_url.append(url.spec());
77 BrowserThread::PostTask( 96 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
78 BrowserThread::UI, FROM_HERE, NewRunnableFunction(OpenURL, string_url)); 97 base::Bind(OpenURL, string_url));
79 } 98 }
80 } 99 }
81 100
82 } // namespace platform_util 101 } // namespace platform_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698