- add sources.
[platform/framework/web/crosswalk.git] / src / remoting / host / setup / win / host_configurer.cc
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
3 // found in the LICENSE file.
4
5 #include <atlbase.h>
6 #include <atlwin.h>
7 #include <ole2.h>
8
9 #include "base/at_exit.h"
10 #include "base/command_line.h"
11 #include "base/run_loop.h"
12 #include "base/threading/thread.h"
13 #include "remoting/base/url_request_context.h"
14 #include "remoting/host/setup/win/host_configurer_window.h"
15
16 class HostConfigurerModule
17     : public ATL::CAtlExeModuleT<HostConfigurerModule> {
18 };
19
20 HostConfigurerModule _AtlModule;
21
22 // An app that runs a HostConfigurerWindow.
23 int WINAPI WinMain(HINSTANCE instance_handle, HINSTANCE prev_instance_handle,
24                    LPSTR cmd_line, int cmd)
25 {
26   // google_apis::GetOAuth2ClientID/Secret need the next line.
27   // On Windows, CommandLine::Init ignores its arguments, and parses
28   // GetCommandLineW directly, so we can pass it dummy arguments.
29   CommandLine::Init(0, NULL);
30
31   // Register and initialize common controls.
32   INITCOMMONCONTROLSEX info;
33   info.dwSize = sizeof(info);
34   info.dwICC = ICC_STANDARD_CLASSES;
35   InitCommonControlsEx(&info);
36
37   // This object instance is required by Chrome code (for example,
38   // FilePath, LazyInstance, MessageLoop).
39   base::AtExitManager exit_manager;
40
41   // Provide message loops and threads for the URLRequestContextGetter.
42   base::MessageLoop message_loop(base::MessageLoop::TYPE_UI);
43   base::Thread io_thread("IO thread");
44   base::Thread::Options io_thread_options(base::MessageLoop::TYPE_IO, 0);
45   io_thread.StartWithOptions(io_thread_options);
46
47   scoped_refptr<net::URLRequestContextGetter> url_request_context_getter_(
48       new remoting::URLRequestContextGetter(io_thread.message_loop_proxy()));
49
50   OleInitialize(NULL);
51
52   // Run a HostConfigurerWindow.
53   remoting::HostConfigurerWindow host_configurer_window(
54       url_request_context_getter_, message_loop.message_loop_proxy(),
55       message_loop.QuitClosure());
56   host_configurer_window.Create(NULL);
57
58   base::RunLoop run_loop;
59   run_loop.Run();
60
61   io_thread.Stop();
62
63   OleUninitialize();
64 }