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

Side by Side Diff: base/win/metro.cc

Issue 10560015: Implement base::win::IsMetroProcess. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/win/metro.h ('k') | chrome/browser/bookmarks/bookmark_manager_extension_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/win/metro.h" 5 #include "base/win/metro.h"
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 8
9 namespace base { 9 namespace base {
10 namespace win { 10 namespace win {
11 11
12 const char kActivateApplication[] = "ActivateApplication"; 12 const char kActivateApplication[] = "ActivateApplication";
13 13
14 HMODULE GetMetroModule() { 14 HMODULE GetMetroModule() {
15 return GetModuleHandleA("metro_driver.dll"); 15 const HMODULE kUninitialized = reinterpret_cast<HMODULE>(1);
16 static HMODULE metro_module = kUninitialized;
17
18 if (metro_module == kUninitialized) {
19 // Initialize the cache, note that the initialization is idempotent
20 // under the assumption that metro_driver is never unloaded, so the
21 // race to this assignment is safe.
22 metro_module = GetModuleHandleA("metro_driver.dll");
23 if (metro_module != NULL) {
24 // This must be a metro process if the metro_driver is loaded.
25 DCHECK(IsMetroProcess());
26 }
27 }
28
29 DCHECK(metro_module != kUninitialized);
30 return metro_module;
31 }
32
33 bool IsMetroProcess() {
34 enum ImmersiveState {
35 kImmersiveUnknown,
36 kImmersiveTrue,
37 kImmersiveFalse
38 };
39 typedef BOOL (WINAPI* IsImmersiveProcessFunc)(HANDLE process);
40
41 // The immersive state of a process can never change.
42 // Look it up once and cache it here.
43 static ImmersiveState state = kImmersiveUnknown;
44
45 if (state == kImmersiveUnknown) {
46 // The lookup hasn't been done yet. Note that the code below here is
47 // idempotent, so it doesn't matter if it races to assignment on multiple
48 // threads.
49 HMODULE user32 = ::GetModuleHandleA("user32.dll");
50 DCHECK(user32 != NULL);
51
52 IsImmersiveProcessFunc is_immersive_process =
53 reinterpret_cast<IsImmersiveProcessFunc>(
54 ::GetProcAddress(user32, "IsImmersiveProcess"));
55
56 if (is_immersive_process != NULL) {
57 if (is_immersive_process(::GetCurrentProcess())) {
58 state = kImmersiveTrue;
59 } else {
60 state = kImmersiveFalse;
61 }
62 } else {
63 // No "IsImmersiveProcess" export on user32.dll, so this is pre-Windows8
64 // and therefore not immersive.
65 state = kImmersiveFalse;
66 }
67 }
68 DCHECK_NE(kImmersiveUnknown, state);
69
70 return state == kImmersiveTrue;
16 } 71 }
17 72
18 wchar_t* LocalAllocAndCopyString(const string16& src) { 73 wchar_t* LocalAllocAndCopyString(const string16& src) {
19 size_t dest_size = (src.length() + 1) * sizeof(wchar_t); 74 size_t dest_size = (src.length() + 1) * sizeof(wchar_t);
20 wchar_t* dest = reinterpret_cast<wchar_t*>(LocalAlloc(LPTR, dest_size)); 75 wchar_t* dest = reinterpret_cast<wchar_t*>(LocalAlloc(LPTR, dest_size));
21 base::wcslcpy(dest, src.c_str(), dest_size); 76 base::wcslcpy(dest, src.c_str(), dest_size);
22 return dest; 77 return dest;
23 } 78 }
24 79
25 } // namespace win 80 } // namespace win
26 } // namespace base 81 } // namespace base
OLDNEW
« no previous file with comments | « base/win/metro.h ('k') | chrome/browser/bookmarks/bookmark_manager_extension_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698