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

Side by Side Diff: chrome/test/chromedriver/chrome_finder.cc

Issue 12848005: [chromedriver] Separate stuff of chrome from chromedriver. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments and fix compile error on mac. Created 7 years, 9 months 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
« no previous file with comments | « chrome/test/chromedriver/chrome_finder.h ('k') | chrome/test/chromedriver/chrome_finder_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/test/chromedriver/chrome_finder.h"
6
7 #include <string>
8 #include <vector>
9
10 #include "base/base_paths.h"
11 #include "base/bind.h"
12 #include "base/callback.h"
13 #include "base/environment.h"
14 #include "base/file_util.h"
15 #include "base/files/file_path.h"
16 #include "base/path_service.h"
17 #include "base/utf_string_conversions.h"
18 #include "build/build_config.h"
19
20 #if defined(OS_WIN)
21 #include "base/win/windows_version.h"
22 #endif
23
24 namespace {
25
26 #if defined(OS_WIN)
27 void GetApplicationDirs(std::vector<base::FilePath>* locations) {
28 // Add user-level location.
29 scoped_ptr<base::Environment> env(base::Environment::Create());
30 std::string home_dir;
31 if (env->GetVar("userprofile", &home_dir)) {
32 base::FilePath default_location(UTF8ToWide(home_dir));
33 if (base::win::GetVersion() < base::win::VERSION_VISTA) {
34 default_location = default_location.Append(
35 L"Local Settings\\Application Data");
36 } else {
37 default_location = default_location.Append(L"AppData\\Local");
38 }
39 locations->push_back(default_location);
40 }
41
42 // Add the system-level location.
43 std::string program_dir;
44 if (env->GetVar("ProgramFiles", &program_dir))
45 locations->push_back(base::FilePath(UTF8ToWide(program_dir)));
46 if (env->GetVar("ProgramFiles(x86)", &program_dir))
47 locations->push_back(base::FilePath(UTF8ToWide(program_dir)));
48 }
49 #elif defined(OS_LINUX)
50 void GetApplicationDirs(std::vector<base::FilePath>* locations) {
51 locations->push_back(base::FilePath("/opt/google/chrome"));
52 locations->push_back(base::FilePath("/usr/local/bin"));
53 locations->push_back(base::FilePath("/usr/local/sbin"));
54 locations->push_back(base::FilePath("/usr/bin"));
55 locations->push_back(base::FilePath("/usr/sbin"));
56 locations->push_back(base::FilePath("/bin"));
57 locations->push_back(base::FilePath("/sbin"));
58 }
59 #endif
60
61 } // namespace
62
63 namespace internal {
64
65 bool FindExe(
66 const base::Callback<bool(const base::FilePath&)>& exists_func,
67 const std::vector<base::FilePath>& rel_paths,
68 const std::vector<base::FilePath>& locations,
69 base::FilePath* out_path) {
70 for (size_t i = 0; i < rel_paths.size(); ++i) {
71 for (size_t j = 0; j < locations.size(); ++j) {
72 base::FilePath path = locations[j].Append(rel_paths[i]);
73 if (exists_func.Run(path)) {
74 *out_path = path;
75 return true;
76 }
77 }
78 }
79 return false;
80 }
81
82 } // namespace internal
83
84 #if defined(OS_MACOSX)
85 void GetApplicationDirs(std::vector<base::FilePath>* locations);
86 #endif
87
88 bool FindChrome(base::FilePath* browser_exe) {
89 #if defined(OS_WIN)
90 base::FilePath browser_exes_array[] = {
91 base::FilePath(L"Google\\Chrome\\Application\\chrome.exe"),
92 base::FilePath(L"Chromium\\Application\\chrome.exe")
93 };
94 #elif defined(OS_MACOSX)
95 base::FilePath browser_exes_array[] = {
96 base::FilePath("Google Chrome.app/Contents/MacOS/Google Chrome"),
97 base::FilePath("Chromium.app/Contents/MacOS/Chromium")
98 };
99 #elif defined(OS_LINUX)
100 base::FilePath browser_exes_array[] = {
101 base::FilePath("google-chrome"),
102 base::FilePath("chrome"),
103 base::FilePath("chromium"),
104 base::FilePath("chromium-browser")
105 };
106 #endif
107 std::vector<base::FilePath> browser_exes(
108 browser_exes_array, browser_exes_array + arraysize(browser_exes_array));
109 std::vector<base::FilePath> locations;
110 GetApplicationDirs(&locations);
111 return internal::FindExe(
112 base::Bind(&file_util::PathExists),
113 browser_exes,
114 locations,
115 browser_exe);
116 }
OLDNEW
« no previous file with comments | « chrome/test/chromedriver/chrome_finder.h ('k') | chrome/test/chromedriver/chrome_finder_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698