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

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: Rename InMetroMode to IsMetroProcess. Cache and DCHECK in GetMetroModule. 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 kNoMetroDriver = reinterpret_cast<HMODULE>(1);
Mark Mentovai 2012/06/18 15:40:22 Optional but highly recommended: I think that thi
Sigurður Ásgeirsson 2012/06/18 18:51:13 Sadly, as we discussed, VS does not implement thre
16 static HMODULE metro_module = NULL;
17
18 if (metro_module == NULL) {
19 HMODULE module = GetModuleHandleA("metro_driver.dll");
20
21 if (module == NULL) {
22 metro_module = kNoMetroDriver;
23 } else {
24 // We must be in a metro process if the metro_driver is loaded.
Mark Mentovai 2012/06/18 15:40:22 All four of your comments in this file say “we,” I
Sigurður Ásgeirsson 2012/06/18 18:51:13 Done.
25 DCHECK(IsMetroProcess());
26 metro_module = module;
27 }
28 }
29 DCHECK(metro_module != NULL);
30
31 if (metro_module == kNoMetroDriver)
32 return NULL;
33
34 return metro_module;
35 }
36
37 bool IsMetroProcess() {
Mark Mentovai 2012/06/18 15:40:22 I’d follow the same pattern for this function too,
Sigurður Ásgeirsson 2012/06/18 18:51:13 Same issue, sadly.
38 enum ImmersiveState {
39 kImmersiveUnknown,
40 kImmersiveTrue,
41 kImmersiveFalse
42 };
43 typedef BOOL (WINAPI* IsImmersiveProcessFunc)(HANDLE process);
44
45 // Since the immersive state of a process can never change, we look it
46 // up once and then cache it here.
47 static ImmersiveState state = kImmersiveUnknown;
48
49 if (state == kImmersiveUnknown) {
50 // We didn't look it up yet. Note that the code below here is idempotent,
51 // so it doesn't matter if it races to assignment on multiple threads.
52 HMODULE user32 = ::GetModuleHandleA("user32.dll");
53 DCHECK(user32 != NULL);
54
55 IsImmersiveProcessFunc is_immersive_process =
56 reinterpret_cast<IsImmersiveProcessFunc>(
57 ::GetProcAddress(user32, "IsImmersiveProcess"));
58
59 if (is_immersive_process != NULL) {
60 if (is_immersive_process(::GetCurrentProcess())) {
61 state = kImmersiveTrue;
62 } else {
63 state = kImmersiveFalse;
64 }
65 } else {
66 // No "IsImmersiveProcess" export on user32.dll, so we're pre-windows8
67 // and therefore not immersive.
68 state = kImmersiveFalse;
69 }
70 }
71 DCHECK_NE(kImmersiveUnknown, state);
72
73 return state == kImmersiveTrue;
16 } 74 }
17 75
18 wchar_t* LocalAllocAndCopyString(const string16& src) { 76 wchar_t* LocalAllocAndCopyString(const string16& src) {
19 size_t dest_size = (src.length() + 1) * sizeof(wchar_t); 77 size_t dest_size = (src.length() + 1) * sizeof(wchar_t);
20 wchar_t* dest = reinterpret_cast<wchar_t*>(LocalAlloc(LPTR, dest_size)); 78 wchar_t* dest = reinterpret_cast<wchar_t*>(LocalAlloc(LPTR, dest_size));
21 base::wcslcpy(dest, src.c_str(), dest_size); 79 base::wcslcpy(dest, src.c_str(), dest_size);
22 return dest; 80 return dest;
23 } 81 }
24 82
25 } // namespace win 83 } // namespace win
26 } // namespace base 84 } // 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