OLD | NEW |
| (Empty) |
1 // Copyright (c) 2006-2008 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 #ifndef CHROME_BROWSER_TAB_CONTENTS_NETWORK_STATUS_VIEW_H_ | |
6 #define CHROME_BROWSER_TAB_CONTENTS_NETWORK_STATUS_VIEW_H_ | |
7 | |
8 #include "base/basictypes.h" | |
9 #include "base/ref_counted.h" | |
10 #include "base/scoped_ptr.h" | |
11 #include "chrome/common/render_messages.h" | |
12 #include "chrome/browser/tab_contents/status_view.h" | |
13 #include "net/url_request/url_request_job_tracker.h" | |
14 | |
15 class MessageLoop; | |
16 class RenderProcessHost; | |
17 class NavigationPerformanceViewer; | |
18 class PageLoadView; | |
19 | |
20 class NetworkStatusView : public StatusView { | |
21 public: | |
22 // button types | |
23 enum { | |
24 IDC_CONFIG_TRACKING_BUTTON = 101, | |
25 IDC_CURRENT_STATUS_BUTTON, | |
26 IDC_CLEAR, | |
27 }; | |
28 | |
29 NetworkStatusView(); | |
30 virtual ~NetworkStatusView(); | |
31 | |
32 // TabContents overrides | |
33 virtual const std::wstring GetDefaultTitle(); | |
34 | |
35 // StatusView implementation | |
36 virtual void OnCreate(const CRect& rect); | |
37 virtual void OnSize(const CRect& rect); | |
38 | |
39 BEGIN_MSG_MAP(NetworkStatusView) | |
40 COMMAND_HANDLER_EX(IDC_CONFIG_TRACKING_BUTTON, BN_CLICKED, OnConfigTrackingC
licked) | |
41 COMMAND_HANDLER_EX(IDC_CURRENT_STATUS_BUTTON, BN_CLICKED, OnCurrentStatusCli
cked) | |
42 COMMAND_HANDLER_EX(IDC_CLEAR, BN_CLICKED, OnClearClicked) | |
43 CHAIN_MSG_MAP(StatusView); | |
44 END_MSG_MAP() | |
45 | |
46 bool is_tracking() const { return is_tracking_; } | |
47 | |
48 private: | |
49 | |
50 // Event handlers | |
51 void OnConfigTrackingClicked(UINT code, int button_id, HWND hwnd); | |
52 void OnCurrentStatusClicked(UINT code, int button_id, HWND hwnd); | |
53 void OnClearClicked(UINT code, int button_id, HWND hwnd); | |
54 | |
55 void AppendText(const std::wstring& text); | |
56 | |
57 // Hide/Show tracking output window | |
58 void HideTrackingResults(); | |
59 void ShowTrackingResults(); | |
60 | |
61 // Clear tracking output | |
62 void ClearTrackingResults(); | |
63 | |
64 // A JobTracker is allocated to monitor network jobs running on the IO | |
65 // thread. This allows the NetworkStatusView to remain single-threaded. | |
66 class JobTracker : public URLRequestJobTracker::JobObserver, | |
67 public base::RefCountedThreadSafe<JobTracker> { | |
68 public: | |
69 JobTracker(NetworkStatusView* view); | |
70 | |
71 // Called by the NetworkStatusView on the main application thread. | |
72 void StartTracking(); | |
73 void StopTracking(); | |
74 void ReportStatus(); | |
75 | |
76 // URLRequestJobTracker::JobObserver methods (called on the IO thread): | |
77 virtual void OnJobAdded(URLRequestJob* job); | |
78 virtual void OnJobRemoved(URLRequestJob* job); | |
79 virtual void OnJobDone(URLRequestJob* job, const URLRequestStatus& status); | |
80 virtual void OnJobRedirect(URLRequestJob* job, const GURL& location, | |
81 int status_code); | |
82 virtual void OnBytesRead(URLRequestJob* job, int byte_count); | |
83 | |
84 // The JobTracker may be deleted after NetworkStatusView is deleted. | |
85 void DetachView() { view_ = NULL; } | |
86 | |
87 private: | |
88 void InvokeOnIOThread(void (JobTracker::*method)()); | |
89 | |
90 // Called on the IO thread | |
91 void OnStartTracking(); | |
92 void OnStopTracking(); | |
93 void OnReportStatus(); | |
94 void AppendText(const std::wstring& text); | |
95 | |
96 // Called on the main thread | |
97 void OnAppendText(const std::wstring& text); | |
98 | |
99 NetworkStatusView* view_; | |
100 MessageLoop* view_message_loop_; | |
101 }; | |
102 friend class JobTracker; | |
103 | |
104 scoped_refptr<JobTracker> tracker_; | |
105 | |
106 bool is_tracking_; | |
107 | |
108 // Textual output of network tracking | |
109 CEdit text_area_; | |
110 | |
111 HFONT monospaced_font_; | |
112 | |
113 DISALLOW_COPY_AND_ASSIGN(NetworkStatusView); | |
114 }; | |
115 | |
116 #endif // #ifndef CHROME_BROWSER_TAB_CONTENTS_NETWORK_STATUS_VIEW_H_ | |
117 | |
OLD | NEW |