Revert 224458 "Enabling MediaStreamInfoBarTest.DenyingCameraDoes..."
[chromium-blink-merge.git] / tools / set_default_handler / set_default_handler_main.cc
blob98e50a985eeef760be1a5913626461985ae721bd
1 // Copyright (c) 2013 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.
5 // Makes a given program ("Google Chrome" by default) the default handler for
6 // some URL protocol ("http" by default) on Windows 8. These defaults can be
7 // overridden via the --program and --protocol command line switches.
9 #include <windows.h>
11 #include "base/at_exit.h"
12 #include "base/command_line.h"
13 #include "base/logging.h"
14 #include "base/strings/string16.h"
15 #include "base/strings/string_util.h"
16 #include "ui/base/win/atl_module.h"
17 #include "win8/test/open_with_dialog_controller.h"
19 namespace {
21 const char kSwitchProgram[] = "program";
22 const char kSwitchProtocol[] = "protocol";
23 const wchar_t kDefaultProgram[] = L"Google Chrome";
24 const wchar_t kDefaultProtocol[] = L"http";
26 } // namespace
28 extern "C"
29 int wmain(int argc, wchar_t* argv[]) {
30 // Initialize the commandline singleton from the environment.
31 CommandLine::Init(0, NULL);
32 // The exit manager is in charge of calling the dtors of singletons.
33 base::AtExitManager exit_manager;
34 logging::LoggingSettings settings;
35 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
36 settings.dcheck_state =
37 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS;
38 logging::InitLogging(settings);
39 logging::SetMinLogLevel(logging::LOG_VERBOSE);
41 ui::win::CreateATLModuleIfNeeded();
43 CommandLine* command_line = CommandLine::ForCurrentProcess();
44 string16 protocol(command_line->GetSwitchValueNative(kSwitchProtocol));
45 if (protocol.empty())
46 protocol = kDefaultProtocol;
48 string16 program(command_line->GetSwitchValueNative(kSwitchProgram));
49 if (program.empty())
50 program = kDefaultProgram;
52 std::vector<string16> choices;
53 HRESULT result = S_OK;
54 win8::OpenWithDialogController controller;
55 result = controller.RunSynchronously(NULL, protocol, program, &choices);
57 if (SUCCEEDED(result)) {
58 printf("success\n");
59 } else if (!choices.empty()) {
60 printf("failed to set program. possible choices: %ls\n",
61 JoinString(choices, L", ").c_str());
62 } else {
63 printf("failed with HRESULT: %0x08X\n", result);
66 return FAILED(result);