Remove ScrollbarLayerImplBase.
[chromium-blink-merge.git] / tools / set_default_handler / set_default_handler_main.cc
blobd7953547f69686117b5ce84bf157a38916ad85bb
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/string16.h"
15 #include "base/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::InitLogging(NULL, logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
35 logging::DONT_LOCK_LOG_FILE,
36 logging::APPEND_TO_OLD_LOG_FILE,
37 logging::ENABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
38 logging::SetMinLogLevel(logging::LOG_VERBOSE);
40 ui::win::CreateATLModuleIfNeeded();
42 CommandLine* command_line = CommandLine::ForCurrentProcess();
43 string16 protocol(command_line->GetSwitchValueNative(kSwitchProtocol));
44 if (protocol.empty())
45 protocol = kDefaultProtocol;
47 string16 program(command_line->GetSwitchValueNative(kSwitchProgram));
48 if (program.empty())
49 program = kDefaultProgram;
51 std::vector<string16> choices;
52 HRESULT result = S_OK;
53 win8::OpenWithDialogController controller;
54 result = controller.RunSynchronously(NULL, protocol, program, &choices);
56 if (SUCCEEDED(result)) {
57 printf("success\n");
58 } else if (!choices.empty()) {
59 printf("failed to set program. possible choices: %ls\n",
60 JoinString(choices, L", ").c_str());
61 } else {
62 printf("failed with HRESULT: 0x08X\n", result);
65 return FAILED(result);