| 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" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 chrome::VersionInfo version_info; |
| 81 if (!version_info.is_valid()) { | |
| 82 NOTREACHED() << "Failed to get current file version"; | |
| 83 // Our own version is invalid. This is an error case. Pretend that we | |
| 84 // are out of date. | |
| 85 return SERVICE_NEWER_VERSION_RUNNING; | |
| 86 } | |
| 87 Version running_version(version_info.Version()); | 81 Version running_version(version_info.Version()); |
| 88 if (!running_version.IsValid()) { | 82 if (!running_version.IsValid()) { |
| 89 NOTREACHED() << "Failed to parse version info"; | 83 NOTREACHED() << "Failed to parse version info"; |
| 90 // Our own version is invalid. This is an error case. Pretend that we | 84 // Our own version is invalid. This is an error case. Pretend that we |
| 91 // are out of date. | 85 // are out of date. |
| 92 return SERVICE_NEWER_VERSION_RUNNING; | 86 return SERVICE_NEWER_VERSION_RUNNING; |
| 93 } | 87 } |
| 94 | 88 |
| 95 if (running_version.CompareTo(service_version) > 0) { | 89 if (running_version.CompareTo(service_version) > 0) { |
| 96 return SERVICE_OLDER_VERSION_RUNNING; | 90 return SERVICE_OLDER_VERSION_RUNNING; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 117 std::string hex_hash = base::HexEncode(hash.c_str(), hash.length()); | 111 std::string hex_hash = base::HexEncode(hash.c_str(), hash.length()); |
| 118 return hex_hash + "." + append_str; | 112 return hex_hash + "." + append_str; |
| 119 } | 113 } |
| 120 | 114 |
| 121 // Return a name that is scoped to this instance of the service process. We | 115 // Return a name that is scoped to this instance of the service process. We |
| 122 // use the user-data-dir and the version as a scoping prefix. | 116 // use the user-data-dir and the version as a scoping prefix. |
| 123 std::string GetServiceProcessScopedVersionedName( | 117 std::string GetServiceProcessScopedVersionedName( |
| 124 const std::string& append_str) { | 118 const std::string& append_str) { |
| 125 std::string versioned_str; | 119 std::string versioned_str; |
| 126 chrome::VersionInfo version_info; | 120 chrome::VersionInfo version_info; |
| 127 DCHECK(version_info.is_valid()); | |
| 128 versioned_str.append(version_info.Version()); | 121 versioned_str.append(version_info.Version()); |
| 129 versioned_str.append(append_str); | 122 versioned_str.append(append_str); |
| 130 return GetServiceProcessScopedName(versioned_str); | 123 return GetServiceProcessScopedName(versioned_str); |
| 131 } | 124 } |
| 132 | 125 |
| 133 // Reads the named shared memory to get the shared data. Returns false if no | 126 // Reads the named shared memory to get the shared data. Returns false if no |
| 134 // matching shared memory was found. | 127 // matching shared memory was found. |
| 135 bool GetServiceProcessData(std::string* version, base::ProcessId* pid) { | 128 bool GetServiceProcessData(std::string* version, base::ProcessId* pid) { |
| 136 scoped_ptr<base::SharedMemory> shared_mem_service_data; | 129 scoped_ptr<base::SharedMemory> shared_mem_service_data; |
| 137 shared_mem_service_data.reset(new base::SharedMemory()); | 130 shared_mem_service_data.reset(new base::SharedMemory()); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 ForceServiceProcessShutdown(running_version, process_id); | 228 ForceServiceProcessShutdown(running_version, process_id); |
| 236 break; | 229 break; |
| 237 case SERVICE_NOT_RUNNING: | 230 case SERVICE_NOT_RUNNING: |
| 238 break; | 231 break; |
| 239 } | 232 } |
| 240 return true; | 233 return true; |
| 241 } | 234 } |
| 242 | 235 |
| 243 bool ServiceProcessState::CreateSharedData() { | 236 bool ServiceProcessState::CreateSharedData() { |
| 244 chrome::VersionInfo version_info; | 237 chrome::VersionInfo version_info; |
| 245 if (!version_info.is_valid()) { | |
| 246 NOTREACHED() << "Failed to get current file version"; | |
| 247 return false; | |
| 248 } | |
| 249 if (version_info.Version().length() >= kMaxVersionStringLength) { | 238 if (version_info.Version().length() >= kMaxVersionStringLength) { |
| 250 NOTREACHED() << "Version string length is << " << | 239 NOTREACHED() << "Version string length is << " << |
| 251 version_info.Version().length() << "which is longer than" << | 240 version_info.Version().length() << "which is longer than" << |
| 252 kMaxVersionStringLength; | 241 kMaxVersionStringLength; |
| 253 return false; | 242 return false; |
| 254 } | 243 } |
| 255 | 244 |
| 256 scoped_ptr<base::SharedMemory> shared_mem_service_data( | 245 scoped_ptr<base::SharedMemory> shared_mem_service_data( |
| 257 new base::SharedMemory()); | 246 new base::SharedMemory()); |
| 258 if (!shared_mem_service_data.get()) | 247 if (!shared_mem_service_data.get()) |
| (...skipping 17 matching lines...) Expand all Loading... |
| 276 shared_data->service_process_pid = base::GetCurrentProcId(); | 265 shared_data->service_process_pid = base::GetCurrentProcId(); |
| 277 shared_mem_service_data_.reset(shared_mem_service_data.release()); | 266 shared_mem_service_data_.reset(shared_mem_service_data.release()); |
| 278 return true; | 267 return true; |
| 279 } | 268 } |
| 280 | 269 |
| 281 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { | 270 IPC::ChannelHandle ServiceProcessState::GetServiceProcessChannel() { |
| 282 return ::GetServiceProcessChannel(); | 271 return ::GetServiceProcessChannel(); |
| 283 } | 272 } |
| 284 | 273 |
| 285 #endif // !OS_MACOSX | 274 #endif // !OS_MACOSX |
| OLD | NEW |