OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 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/browser/mac/timezone_notification.h" |
| 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 #import <Foundation/Foundation.h> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "content/public/browser/render_view_host.h" |
| 14 #include "content/public/browser/render_widget_host.h" |
| 15 #include "content/public/browser/render_widget_host_iterator.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 void NotifyRenderers() { |
| 20 scoped_ptr<content::RenderWidgetHostIterator> widgets( |
| 21 content::RenderWidgetHost::GetRenderWidgetHosts()); |
| 22 while (content::RenderWidgetHost* widget = widgets->GetNextHost()) { |
| 23 if (widget->IsRenderView()) { |
| 24 content::RenderViewHost* view = content::RenderViewHost::From(widget); |
| 25 view->NotifyTimezoneChange(); |
| 26 } |
| 27 } |
| 28 } |
| 29 |
| 30 } // namespace |
| 31 |
| 32 @interface TimeZoneWatcher : NSObject |
| 33 - (void)systemTimeZoneDidChange:(NSNotification*)notification; |
| 34 @end |
| 35 |
| 36 @implementation TimeZoneWatcher |
| 37 |
| 38 - (id)init { |
| 39 if ((self = [super init])) { |
| 40 NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; |
| 41 [nc addObserver:self |
| 42 selector:@selector(systemTimeZoneDidChange:) |
| 43 name:NSSystemTimeZoneDidChangeNotification |
| 44 object:nil]; |
| 45 } |
| 46 return self; |
| 47 } |
| 48 |
| 49 - (void)dealloc { |
| 50 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 51 return [super dealloc]; |
| 52 } |
| 53 |
| 54 - (void)systemTimeZoneDidChange:(NSNotification*)notification { |
| 55 NotifyRenderers(); |
| 56 } |
| 57 |
| 58 void ListenForTimeZoneChanges() { |
| 59 DCHECK_EQ(CFRunLoopGetCurrent(), CFRunLoopGetMain()); |
| 60 static TimeZoneWatcher* tzw ALLOW_UNUSED = [[TimeZoneWatcher alloc] init]; |
| 61 } |
| 62 |
| 63 @end |
OLD | NEW |