Chromium Code Reviews| 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 #import "chrome/browser/mac/keystone_glue.h" | 5 #import "chrome/browser/mac/keystone_glue.h" |
| 6 | 6 |
| 7 #include <sys/mount.h> | 7 #include <sys/mount.h> |
| 8 #include <sys/param.h> | 8 #include <sys/param.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 | 10 |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/mac/authorization_util.h" | 16 #include "base/mac/authorization_util.h" |
| 17 #include "base/mac/bundle_locations.h" | 17 #include "base/mac/bundle_locations.h" |
| 18 #include "base/mac/foundation_util.h" | 18 #include "base/mac/foundation_util.h" |
| 19 #include "base/mac/mac_logging.h" | 19 #include "base/mac/mac_logging.h" |
| 20 #include "base/mac/scoped_nsautorelease_pool.h" | 20 #include "base/mac/scoped_nsautorelease_pool.h" |
| 21 #include "base/memory/ref_counted.h" | 21 #include "base/memory/ref_counted.h" |
| 22 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
| 23 #include "base/strings/sys_string_conversions.h" | 23 #include "base/strings/sys_string_conversions.h" |
| 24 #include "base/threading/worker_pool.h" | 24 #include "base/task_scheduler/post_task.h" |
| 25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
| 26 #import "chrome/browser/mac/keystone_registration.h" | 26 #import "chrome/browser/mac/keystone_registration.h" |
| 27 #include "chrome/common/channel_info.h" | 27 #include "chrome/common/channel_info.h" |
| 28 #include "chrome/common/chrome_constants.h" | 28 #include "chrome/common/chrome_constants.h" |
| 29 #include "chrome/grit/chromium_strings.h" | 29 #include "chrome/grit/chromium_strings.h" |
| 30 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
| 31 #include "components/version_info/version_info.h" | 31 #include "components/version_info/version_info.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "ui/base/l10n/l10n_util_mac.h" | 33 #include "ui/base/l10n/l10n_util_mac.h" |
| 34 | 34 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 53 NSString* kBrandUserFile = @"~/Library/Google/" kBrandFileName; | 53 NSString* kBrandUserFile = @"~/Library/Google/" kBrandFileName; |
| 54 NSString* kBrandSystemFile = @"/Library/Google/" kBrandFileName; | 54 NSString* kBrandSystemFile = @"/Library/Google/" kBrandFileName; |
| 55 | 55 |
| 56 NSString* UserBrandFilePath() { | 56 NSString* UserBrandFilePath() { |
| 57 return [kBrandUserFile stringByStandardizingPath]; | 57 return [kBrandUserFile stringByStandardizingPath]; |
| 58 } | 58 } |
| 59 NSString* SystemBrandFilePath() { | 59 NSString* SystemBrandFilePath() { |
| 60 return [kBrandSystemFile stringByStandardizingPath]; | 60 return [kBrandSystemFile stringByStandardizingPath]; |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Adaptor for scheduling an Objective-C method call on a |WorkerPool| | 63 // Adaptor for scheduling an Objective-C method call in TaskScheduler. |
| 64 // thread. | |
| 65 class PerformBridge : public base::RefCountedThreadSafe<PerformBridge> { | 64 class PerformBridge : public base::RefCountedThreadSafe<PerformBridge> { |
| 66 public: | 65 public: |
| 67 | 66 |
| 68 // Call |sel| on |target| with |arg| in a WorkerPool thread. | 67 // Call |sel| on |target| with |arg| in a WorkerPool thread. |
| 69 // |target| and |arg| are retained, |arg| may be |nil|. | 68 // |target| and |arg| are retained, |arg| may be |nil|. |
| 70 static void PostPerform(id target, SEL sel, id arg) { | 69 static void PostPerform(id target, SEL sel, id arg) { |
| 71 DCHECK(target); | 70 DCHECK(target); |
| 72 DCHECK(sel); | 71 DCHECK(sel); |
| 73 | 72 |
| 74 scoped_refptr<PerformBridge> op = new PerformBridge(target, sel, arg); | 73 scoped_refptr<PerformBridge> op = new PerformBridge(target, sel, arg); |
| 75 base::WorkerPool::PostTask( | 74 base::PostTaskWithTraits( |
| 76 FROM_HERE, base::Bind(&PerformBridge::Run, op.get()), true); | 75 FROM_HERE, base::TaskTraits() |
| 76 .WithFileIO() | |
| 77 .WithPriority(base::TaskPriority::BACKGROUND) | |
| 78 .WithShutdownBehavior( | |
| 79 base::TaskShutdownBehavior::CONTINUE_ON_SHUTDOWN), | |
|
Mark Mentovai
2016/11/29 21:56:06
Revise change description to match this.
fdoray
2016/11/30 19:25:21
Done.
| |
| 80 base::Bind(&PerformBridge::Run, op.get())); | |
| 77 } | 81 } |
| 78 | 82 |
| 79 // Convenience for the no-argument case. | 83 // Convenience for the no-argument case. |
| 80 static void PostPerform(id target, SEL sel) { | 84 static void PostPerform(id target, SEL sel) { |
| 81 PostPerform(target, sel, nil); | 85 PostPerform(target, sel, nil); |
| 82 } | 86 } |
| 83 | 87 |
| 84 private: | 88 private: |
| 85 // Allow RefCountedThreadSafe<> to delete. | 89 // Allow RefCountedThreadSafe<> to delete. |
| 86 friend class base::RefCountedThreadSafe<PerformBridge>; | 90 friend class base::RefCountedThreadSafe<PerformBridge>; |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 701 NSDictionary* infoPlist = | 705 NSDictionary* infoPlist = |
| 702 [NSDictionary dictionaryWithContentsOfFile:appInfoPlistPath]; | 706 [NSDictionary dictionaryWithContentsOfFile:appInfoPlistPath]; |
| 703 return base::mac::ObjCCast<NSString>( | 707 return base::mac::ObjCCast<NSString>( |
| 704 [infoPlist objectForKey:@"CFBundleShortVersionString"]); | 708 [infoPlist objectForKey:@"CFBundleShortVersionString"]); |
| 705 } | 709 } |
| 706 | 710 |
| 707 // Runs on the main thread. | 711 // Runs on the main thread. |
| 708 - (void)determineUpdateStatusAsync { | 712 - (void)determineUpdateStatusAsync { |
| 709 DCHECK([NSThread isMainThread]); | 713 DCHECK([NSThread isMainThread]); |
| 710 | 714 |
| 711 PerformBridge::PostPerform(self, @selector(determineUpdateStatus)); | 715 PerformBridge::PostPerform(self, @selector(determineUpdateStatus)); |
|
Mark Mentovai
2016/11/29 21:56:06
I think that this one could be SKIP_ON_SHUTDOWN…
fdoray
2016/11/30 19:25:21
Are you sure?
CONTINUE_ON_SHUTDOWN tasks are not
Mark Mentovai
2016/11/30 19:53:00
OK, that’s confusing terminology to me, but it sou
| |
| 712 } | 716 } |
| 713 | 717 |
| 714 // Runs on a thread managed by WorkerPool. | 718 // Runs on a thread managed by WorkerPool. |
| 715 - (void)determineUpdateStatus { | 719 - (void)determineUpdateStatus { |
| 716 DCHECK(![NSThread isMainThread]); | 720 DCHECK(![NSThread isMainThread]); |
| 717 | 721 |
| 718 NSString* version = [self currentlyInstalledVersion]; | 722 NSString* version = [self currentlyInstalledVersion]; |
| 719 | 723 |
| 720 [self performSelectorOnMainThread:@selector(determineUpdateStatusForVersion:) | 724 [self performSelectorOnMainThread:@selector(determineUpdateStatusForVersion:) |
| 721 withObject:version | 725 withObject:version |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1061 // on the main thread before jumping over to a WorkerPool-managed | 1065 // on the main thread before jumping over to a WorkerPool-managed |
| 1062 // thread to run the tool. | 1066 // thread to run the tool. |
| 1063 DCHECK([NSThread isMainThread]); | 1067 DCHECK([NSThread isMainThread]); |
| 1064 | 1068 |
| 1065 SEL selector = @selector(changePermissionsForPromotionWithTool:); | 1069 SEL selector = @selector(changePermissionsForPromotionWithTool:); |
| 1066 NSString* toolPath = | 1070 NSString* toolPath = |
| 1067 [base::mac::FrameworkBundle() | 1071 [base::mac::FrameworkBundle() |
| 1068 pathForResource:@"keystone_promote_postflight" | 1072 pathForResource:@"keystone_promote_postflight" |
| 1069 ofType:@"sh"]; | 1073 ofType:@"sh"]; |
| 1070 | 1074 |
| 1071 PerformBridge::PostPerform(self, selector, toolPath); | 1075 PerformBridge::PostPerform(self, selector, toolPath); |
|
Mark Mentovai
2016/11/29 21:56:06
…but this one should be CONTINUE_ON_SHUTDOWN, beca
fdoray
2016/11/30 19:25:21
You want to make sure that this task runs to compl
Mark Mentovai
2016/11/30 19:53:00
Yes, that’s what I was saying.
| |
| 1072 } | 1076 } |
| 1073 | 1077 |
| 1074 - (void)changePermissionsForPromotionWithTool:(NSString*)toolPath { | 1078 - (void)changePermissionsForPromotionWithTool:(NSString*)toolPath { |
| 1075 const char* toolPathC = [toolPath fileSystemRepresentation]; | 1079 const char* toolPathC = [toolPath fileSystemRepresentation]; |
| 1076 | 1080 |
| 1077 const char* appPathC = [appPath_ fileSystemRepresentation]; | 1081 const char* appPathC = [appPath_ fileSystemRepresentation]; |
| 1078 const char* arguments[] = {appPathC, NULL}; | 1082 const char* arguments[] = {appPathC, NULL}; |
| 1079 | 1083 |
| 1080 int exit_status; | 1084 int exit_status; |
| 1081 OSStatus status = base::mac::ExecuteWithPrivilegesAndWait( | 1085 OSStatus status = base::mac::ExecuteWithPrivilegesAndWait( |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1191 return [KeystoneGlue defaultKeystoneGlue] != nil; | 1195 return [KeystoneGlue defaultKeystoneGlue] != nil; |
| 1192 } | 1196 } |
| 1193 | 1197 |
| 1194 base::string16 CurrentlyInstalledVersion() { | 1198 base::string16 CurrentlyInstalledVersion() { |
| 1195 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; | 1199 KeystoneGlue* keystoneGlue = [KeystoneGlue defaultKeystoneGlue]; |
| 1196 NSString* version = [keystoneGlue currentlyInstalledVersion]; | 1200 NSString* version = [keystoneGlue currentlyInstalledVersion]; |
| 1197 return base::SysNSStringToUTF16(version); | 1201 return base::SysNSStringToUTF16(version); |
| 1198 } | 1202 } |
| 1199 | 1203 |
| 1200 } // namespace keystone_glue | 1204 } // namespace keystone_glue |
| OLD | NEW |