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/common/service_process_util.h" | 5 #include "chrome/common/service_process_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
13 #include "base/sha1.h" | 13 #include "base/sha1.h" |
14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "base/version.h" | 18 #include "base/version.h" |
19 #include "chrome/common/chrome_constants.h" | 19 #include "chrome/common/chrome_constants.h" |
20 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
22 #include "chrome/common/chrome_version_info.h" | |
23 #include "components/cloud_devices/common/cloud_devices_switches.h" | 22 #include "components/cloud_devices/common/cloud_devices_switches.h" |
| 23 #include "components/version_info/version_info.h" |
24 #include "content/public/common/content_paths.h" | 24 #include "content/public/common/content_paths.h" |
25 #include "google_apis/gaia/gaia_switches.h" | 25 #include "google_apis/gaia/gaia_switches.h" |
26 #include "ui/base/ui_base_switches.h" | 26 #include "ui/base/ui_base_switches.h" |
27 | 27 |
28 #if !defined(OS_MACOSX) | 28 #if !defined(OS_MACOSX) |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 // This should be more than enough to hold a version string assuming each part | 32 // This should be more than enough to hold a version string assuming each part |
33 // of the version string is an int64. | 33 // of the version string is an int64. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // At this time we have a version string. Set the out param if it exists. | 70 // At this time we have a version string. Set the out param if it exists. |
71 if (service_version_out) | 71 if (service_version_out) |
72 *service_version_out = version; | 72 *service_version_out = version; |
73 | 73 |
74 Version service_version(version); | 74 Version service_version(version); |
75 // If the version string is invalid, treat it like an older version. | 75 // If the version string is invalid, treat it like an older version. |
76 if (!service_version.IsValid()) | 76 if (!service_version.IsValid()) |
77 return SERVICE_OLDER_VERSION_RUNNING; | 77 return SERVICE_OLDER_VERSION_RUNNING; |
78 | 78 |
79 // Get the version of the currently *running* instance of Chrome. | 79 // Get the version of the currently *running* instance of Chrome. |
80 chrome::VersionInfo version_info; | 80 Version running_version(version_info::GetVersionNumber()); |
81 Version running_version(version_info.Version()); | |
82 if (!running_version.IsValid()) { | 81 if (!running_version.IsValid()) { |
83 NOTREACHED() << "Failed to parse version info"; | 82 NOTREACHED() << "Failed to parse version info"; |
84 // Our own version is invalid. This is an error case. Pretend that we | 83 // Our own version is invalid. This is an error case. Pretend that we |
85 // are out of date. | 84 // are out of date. |
86 return SERVICE_NEWER_VERSION_RUNNING; | 85 return SERVICE_NEWER_VERSION_RUNNING; |
87 } | 86 } |
88 | 87 |
89 if (running_version.CompareTo(service_version) > 0) { | 88 if (running_version.CompareTo(service_version) > 0) { |
90 return SERVICE_OLDER_VERSION_RUNNING; | 89 return SERVICE_OLDER_VERSION_RUNNING; |
91 } else if (service_version.CompareTo(running_version) > 0) { | 90 } else if (service_version.CompareTo(running_version) > 0) { |
92 return SERVICE_NEWER_VERSION_RUNNING; | 91 return SERVICE_NEWER_VERSION_RUNNING; |
93 } | 92 } |
94 return SERVICE_SAME_VERSION_RUNNING; | 93 return SERVICE_SAME_VERSION_RUNNING; |
95 } | 94 } |
96 | 95 |
97 } // namespace | 96 } // namespace |
98 | 97 |
99 | 98 |
100 // Return a name that is scoped to this instance of the service process. We | 99 // Return a name that is scoped to this instance of the service process. We |
101 // use the user-data-dir and the version as a scoping prefix. | 100 // use the user-data-dir and the version as a scoping prefix. |
102 std::string GetServiceProcessScopedVersionedName( | 101 std::string GetServiceProcessScopedVersionedName( |
103 const std::string& append_str) { | 102 const std::string& append_str) { |
104 std::string versioned_str; | 103 std::string versioned_str; |
105 chrome::VersionInfo version_info; | 104 versioned_str.append(version_info::GetVersionNumber()); |
106 versioned_str.append(version_info.Version()); | |
107 versioned_str.append(append_str); | 105 versioned_str.append(append_str); |
108 return GetServiceProcessScopedName(versioned_str); | 106 return GetServiceProcessScopedName(versioned_str); |
109 } | 107 } |
110 | 108 |
111 // Reads the named shared memory to get the shared data. Returns false if no | 109 // Reads the named shared memory to get the shared data. Returns false if no |
112 // matching shared memory was found. | 110 // matching shared memory was found. |
113 bool GetServiceProcessData(std::string* version, base::ProcessId* pid) { | 111 bool GetServiceProcessData(std::string* version, base::ProcessId* pid) { |
114 scoped_ptr<base::SharedMemory> shared_mem_service_data; | 112 scoped_ptr<base::SharedMemory> shared_mem_service_data; |
115 shared_mem_service_data.reset(new base::SharedMemory()); | 113 shared_mem_service_data.reset(new base::SharedMemory()); |
116 ServiceProcessSharedData* service_data = NULL; | 114 ServiceProcessSharedData* service_data = NULL; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 // If an older version is running, kill it. | 226 // If an older version is running, kill it. |
229 ForceServiceProcessShutdown(running_version, process_id); | 227 ForceServiceProcessShutdown(running_version, process_id); |
230 break; | 228 break; |
231 case SERVICE_NOT_RUNNING: | 229 case SERVICE_NOT_RUNNING: |
232 break; | 230 break; |
233 } | 231 } |
234 return true; | 232 return true; |
235 } | 233 } |
236 | 234 |
237 bool ServiceProcessState::CreateSharedData() { | 235 bool ServiceProcessState::CreateSharedData() { |
238 chrome::VersionInfo version_info; | 236 if (version_info::GetVersionNumber().length() >= kMaxVersionStringLength) { |
239 if (version_info.Version().length() >= kMaxVersionStringLength) { | 237 NOTREACHED() << "Version string length is << " |
240 NOTREACHED() << "Version string length is << " << | 238 << version_info::GetVersionNumber().length() |
241 version_info.Version().length() << "which is longer than" << | 239 << " which is longer than" << kMaxVersionStringLength; |
242 kMaxVersionStringLength; | |
243 return false; | 240 return false; |
244 } | 241 } |
245 | 242 |
246 scoped_ptr<base::SharedMemory> shared_mem_service_data( | 243 scoped_ptr<base::SharedMemory> shared_mem_service_data( |
247 new base::SharedMemory()); | 244 new base::SharedMemory()); |
248 if (!shared_mem_service_data.get()) | 245 if (!shared_mem_service_data.get()) |
249 return false; | 246 return false; |
250 | 247 |
251 uint32 alloc_size = sizeof(ServiceProcessSharedData); | 248 uint32 alloc_size = sizeof(ServiceProcessSharedData); |
252 // TODO(viettrungluu): Named shared memory is deprecated (crbug.com/345734). | 249 // TODO(viettrungluu): Named shared memory is deprecated (crbug.com/345734). |
253 if (!shared_mem_service_data->CreateNamedDeprecated | 250 if (!shared_mem_service_data->CreateNamedDeprecated |
254 (GetServiceProcessSharedMemName(), true, alloc_size)) | 251 (GetServiceProcessSharedMemName(), true, alloc_size)) |
255 return false; | 252 return false; |
256 | 253 |
257 if (!shared_mem_service_data->Map(alloc_size)) | 254 if (!shared_mem_service_data->Map(alloc_size)) |
258 return false; | 255 return false; |
259 | 256 |
260 memset(shared_mem_service_data->memory(), 0, alloc_size); | 257 memset(shared_mem_service_data->memory(), 0, alloc_size); |
261 ServiceProcessSharedData* shared_data = | 258 ServiceProcessSharedData* shared_data = |
262 reinterpret_cast<ServiceProcessSharedData*>( | 259 reinterpret_cast<ServiceProcessSharedData*>( |
263 shared_mem_service_data->memory()); | 260 shared_mem_service_data->memory()); |
264 memcpy(shared_data->service_process_version, version_info.Version().c_str(), | 261 memcpy(shared_data->service_process_version, |
265 version_info.Version().length()); | 262 version_info::GetVersionNumber().c_str(), |
| 263 version_info::GetVersionNumber().length()); |
266 shared_data->service_process_pid = base::GetCurrentProcId(); | 264 shared_data->service_process_pid = base::GetCurrentProcId(); |
267 shared_mem_service_data_.reset(shared_mem_service_data.release()); | 265 shared_mem_service_data_.reset(shared_mem_service_data.release()); |
268 return true; | 266 return true; |
269 } | 267 } |
270 | 268 |
271 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { | 269 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { |
272 return ::GetServiceProcessChannel(); | 270 return ::GetServiceProcessChannel(); |
273 } | 271 } |
274 | 272 |
275 #endif // !OS_MACOSX | 273 #endif // !OS_MACOSX |
OLD | NEW |