| 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 "ui/aura/env.h" | 5 #include "ui/aura/env.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 8 #include "base/threading/thread_local.h" | 9 #include "base/threading/thread_local.h" |
| 9 #include "ui/aura/env_observer.h" | 10 #include "ui/aura/env_observer.h" |
| 10 #include "ui/aura/input_state_lookup.h" | 11 #include "ui/aura/input_state_lookup.h" |
| 11 #include "ui/events/event_target_iterator.h" | 12 #include "ui/events/event_target_iterator.h" |
| 12 #include "ui/events/platform/platform_event_source.h" | 13 #include "ui/events/platform/platform_event_source.h" |
| 13 | 14 |
| 14 #if defined(USE_OZONE) | 15 #if defined(USE_OZONE) |
| 15 #include "ui/ozone/public/ozone_platform.h" | 16 #include "ui/ozone/public/ozone_platform.h" |
| 16 #endif | 17 #endif |
| 17 | 18 |
| 18 namespace aura { | 19 namespace aura { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // Env is thread local so that aura may be used on multiple threads. | 23 // Env is thread local so that aura may be used on multiple threads. |
| 23 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = | 24 base::LazyInstance<base::ThreadLocalPointer<Env> >::Leaky lazy_tls_ptr = |
| 24 LAZY_INSTANCE_INITIALIZER; | 25 LAZY_INSTANCE_INITIALIZER; |
| 25 | 26 |
| 27 #if defined(USE_OZONE) |
| 28 // Returns true if running inside of mus. Checks for mojo specific flag. |
| 29 bool RunningInsideMus() { |
| 30 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 31 "primordial-pipe-token"); |
| 32 } |
| 33 #endif |
| 34 |
| 26 } // namespace | 35 } // namespace |
| 27 | 36 |
| 28 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
| 29 // Env, public: | 38 // Env, public: |
| 30 | 39 |
| 31 // static | 40 // static |
| 32 void Env::CreateInstance(bool create_event_source) { | 41 void Env::CreateInstance(bool create_event_source) { |
| 33 if (!lazy_tls_ptr.Pointer()->Get()) | 42 if (!lazy_tls_ptr.Pointer()->Get()) |
| 34 (new Env())->Init(create_event_source); | 43 (new Env())->Init(create_event_source); |
| 35 } | 44 } |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWillDestroyEnv()); | 90 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWillDestroyEnv()); |
| 82 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); | 91 DCHECK_EQ(this, lazy_tls_ptr.Pointer()->Get()); |
| 83 lazy_tls_ptr.Pointer()->Set(NULL); | 92 lazy_tls_ptr.Pointer()->Set(NULL); |
| 84 } | 93 } |
| 85 | 94 |
| 86 void Env::Init(bool create_event_source) { | 95 void Env::Init(bool create_event_source) { |
| 87 if (!create_event_source) | 96 if (!create_event_source) |
| 88 return; | 97 return; |
| 89 #if defined(USE_OZONE) | 98 #if defined(USE_OZONE) |
| 90 // The ozone platform can provide its own event source. So initialize the | 99 // The ozone platform can provide its own event source. So initialize the |
| 91 // platform before creating the default event source. | 100 // platform before creating the default event source. If running inside mus |
| 92 ui::OzonePlatform::InitializeForUI(); | 101 // let the mus process initialize ozone instead. |
| 102 if (!RunningInsideMus()) |
| 103 ui::OzonePlatform::InitializeForUI(); |
| 93 #endif | 104 #endif |
| 94 if (!ui::PlatformEventSource::GetInstance()) | 105 if (!ui::PlatformEventSource::GetInstance()) |
| 95 event_source_ = ui::PlatformEventSource::CreateDefault(); | 106 event_source_ = ui::PlatformEventSource::CreateDefault(); |
| 96 } | 107 } |
| 97 | 108 |
| 98 void Env::NotifyWindowInitialized(Window* window) { | 109 void Env::NotifyWindowInitialized(Window* window) { |
| 99 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWindowInitialized(window)); | 110 FOR_EACH_OBSERVER(EnvObserver, observers_, OnWindowInitialized(window)); |
| 100 } | 111 } |
| 101 | 112 |
| 102 void Env::NotifyHostInitialized(WindowTreeHost* host) { | 113 void Env::NotifyHostInitialized(WindowTreeHost* host) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 121 scoped_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { | 132 scoped_ptr<ui::EventTargetIterator> Env::GetChildIterator() const { |
| 122 return nullptr; | 133 return nullptr; |
| 123 } | 134 } |
| 124 | 135 |
| 125 ui::EventTargeter* Env::GetEventTargeter() { | 136 ui::EventTargeter* Env::GetEventTargeter() { |
| 126 NOTREACHED(); | 137 NOTREACHED(); |
| 127 return NULL; | 138 return NULL; |
| 128 } | 139 } |
| 129 | 140 |
| 130 } // namespace aura | 141 } // namespace aura |
| OLD | NEW |