| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/device_sharing/device_sharing_manager.h" | 5 #include "ios/chrome/browser/device_sharing/device_sharing_manager.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #import "components/handoff/handoff_manager.h" | 10 #import "components/handoff/handoff_manager.h" |
| 11 #include "components/prefs/pref_change_registrar.h" | 11 #include "components/prefs/pref_change_registrar.h" |
| 12 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
| 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 13 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 14 #include "ios/chrome/browser/pref_names.h" | 14 #include "ios/chrome/browser/pref_names.h" |
| 15 #include "ios/chrome/browser/prefs/pref_observer_bridge.h" | 15 #include "ios/chrome/browser/prefs/pref_observer_bridge.h" |
| 16 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 17 | 17 |
| 18 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 19 #error "This file requires ARC support." |
| 20 #endif |
| 21 |
| 18 @interface DeviceSharingManager ()<PrefObserverDelegate> { | 22 @interface DeviceSharingManager ()<PrefObserverDelegate> { |
| 19 ios::ChromeBrowserState* _browserState; // weak | 23 ios::ChromeBrowserState* _browserState; // weak |
| 20 | 24 |
| 21 // Bridge to listen to pref changes to the active browser state. | 25 // Bridge to listen to pref changes to the active browser state. |
| 22 std::unique_ptr<PrefObserverBridge> _browserStatePrefObserverBridge; | 26 std::unique_ptr<PrefObserverBridge> _browserStatePrefObserverBridge; |
| 23 | 27 |
| 24 // Registrar for pref change notifications to the active browser state. | 28 // Registrar for pref change notifications to the active browser state. |
| 25 std::unique_ptr<PrefChangeRegistrar> _browserStatePrefChangeRegistrar; | 29 std::unique_ptr<PrefChangeRegistrar> _browserStatePrefChangeRegistrar; |
| 26 | 30 |
| 27 // Responsible for maintaining all state related to the Handoff feature. | 31 // Responsible for maintaining all state related to the Handoff feature. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 - (void)updateHandoffManager { | 74 - (void)updateHandoffManager { |
| 71 BOOL handoffEnabled = | 75 BOOL handoffEnabled = |
| 72 _browserState && | 76 _browserState && |
| 73 _browserState->GetPrefs()->GetBoolean(prefs::kIosHandoffToOtherDevices); | 77 _browserState->GetPrefs()->GetBoolean(prefs::kIosHandoffToOtherDevices); |
| 74 if (!handoffEnabled) { | 78 if (!handoffEnabled) { |
| 75 _handoffManager.reset(); | 79 _handoffManager.reset(); |
| 76 return; | 80 return; |
| 77 } | 81 } |
| 78 | 82 |
| 79 if (!_handoffManager) | 83 if (!_handoffManager) |
| 80 _handoffManager.reset([[[self class] createHandoffManager] retain]); | 84 _handoffManager.reset([[self class] createHandoffManager]); |
| 81 } | 85 } |
| 82 | 86 |
| 83 + (HandoffManager*)createHandoffManager { | 87 + (HandoffManager*)createHandoffManager { |
| 84 return [[[HandoffManager alloc] init] autorelease]; | 88 return [[HandoffManager alloc] init]; |
| 85 } | 89 } |
| 86 | 90 |
| 87 #pragma mark - PrefObserverDelegate | 91 #pragma mark - PrefObserverDelegate |
| 88 | 92 |
| 89 - (void)onPreferenceChanged:(const std::string&)preferenceName { | 93 - (void)onPreferenceChanged:(const std::string&)preferenceName { |
| 90 if (preferenceName == prefs::kIosHandoffToOtherDevices) { | 94 if (preferenceName == prefs::kIosHandoffToOtherDevices) { |
| 91 [self updateHandoffManager]; | 95 [self updateHandoffManager]; |
| 92 } | 96 } |
| 93 } | 97 } |
| 94 | 98 |
| 95 @end | 99 @end |
| 96 | 100 |
| 97 @implementation DeviceSharingManager (TestingOnly) | 101 @implementation DeviceSharingManager (TestingOnly) |
| 98 | 102 |
| 99 - (HandoffManager*)handoffManager { | 103 - (HandoffManager*)handoffManager { |
| 100 return _handoffManager.get(); | 104 return _handoffManager.get(); |
| 101 } | 105 } |
| 102 | 106 |
| 103 @end | 107 @end |
| OLD | NEW |