Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3686)

Unified Diff: chrome/browser/mac/timezone_notification.mm

Issue 183763041: Listen for changes to the system time zone, and broadcast a NotifyTimezoneChange to all RenderViewHo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/mac/timezone_notification.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/mac/timezone_notification.mm
diff --git a/chrome/browser/mac/timezone_notification.mm b/chrome/browser/mac/timezone_notification.mm
new file mode 100644
index 0000000000000000000000000000000000000000..1f9d65bd6cd27c43455a0f2512152d888d1bc01f
--- /dev/null
+++ b/chrome/browser/mac/timezone_notification.mm
@@ -0,0 +1,63 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/mac/timezone_notification.h"
+
+#include <CoreFoundation/CoreFoundation.h>
+#import <Foundation/Foundation.h>
+
+#include "base/compiler_specific.h"
+#include "base/logging.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/render_widget_host.h"
+#include "content/public/browser/render_widget_host_iterator.h"
+
+namespace {
+
+void NotifyRenderers() {
+ scoped_ptr<content::RenderWidgetHostIterator> widgets(
+ content::RenderWidgetHost::GetRenderWidgetHosts());
+ while (content::RenderWidgetHost* widget = widgets->GetNextHost()) {
+ if (widget->IsRenderView()) {
+ content::RenderViewHost* view = content::RenderViewHost::From(widget);
+ view->NotifyTimezoneChange();
+ }
+ }
+}
+
+} // namespace
+
+@interface TimeZoneWatcher : NSObject
+- (void)systemTimeZoneDidChange:(NSNotification*)notification;
+@end
+
+@implementation TimeZoneWatcher
+
+- (id)init {
+ if ((self = [super init])) {
+ NSNotificationCenter* nc = [NSNotificationCenter defaultCenter];
+ [nc addObserver:self
+ selector:@selector(systemTimeZoneDidChange:)
+ name:NSSystemTimeZoneDidChangeNotification
+ object:nil];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ return [super dealloc];
+}
+
+- (void)systemTimeZoneDidChange:(NSNotification*)notification {
+ NotifyRenderers();
+}
+
+void ListenForTimeZoneChanges() {
+ DCHECK_EQ(CFRunLoopGetCurrent(), CFRunLoopGetMain());
+ static TimeZoneWatcher* tzw ALLOW_UNUSED = [[TimeZoneWatcher alloc] init];
+}
+
+@end
« no previous file with comments | « chrome/browser/mac/timezone_notification.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698