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

Side by Side Diff: chrome/browser/local_discovery/privet_traffic_detector.h

Issue 1553333002: Move cloud print specific files out of local_discovery (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@moveprn
Patch Set: Created 4 years, 11 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
OLDNEW
(Empty)
1 // Copyright 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.
4
5 #ifndef CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_TRAFFIC_DETECTOR_H_
6 #define CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_TRAFFIC_DETECTOR_H_
7
8 #include "base/callback.h"
9 #include "base/cancelable_callback.h"
10 #include "base/macros.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "net/base/address_family.h"
13 #include "net/base/ip_endpoint.h"
14 #include "net/base/network_change_notifier.h"
15
16 namespace net {
17 class DatagramServerSocket;
18 class IOBufferWithSize;
19 }
20
21 namespace local_discovery {
22
23 // Detects mDns traffic that looks like "Privet" protocol.
24 // Can produce false positives results, but main task of the class is to avoid
25 // running full mDns listener if user doesn't have devices.
26 // When traffic is detected, class fires callback and shutdowns itself.
27 class PrivetTrafficDetector
28 : public base::RefCountedThreadSafe<
29 PrivetTrafficDetector, content::BrowserThread::DeleteOnIOThread>,
30 private net::NetworkChangeNotifier::NetworkChangeObserver {
31 public:
32 PrivetTrafficDetector(net::AddressFamily address_family,
33 const base::Closure& on_traffic_detected);
34
35 void Start();
36
37 private:
38 friend struct content::BrowserThread::DeleteOnThread<
39 content::BrowserThread::IO>;
40 friend class base::DeleteHelper<PrivetTrafficDetector>;
41 ~PrivetTrafficDetector() override;
42
43 // net::NetworkChangeNotifier::NetworkChangeObserver implementation.
44 void OnNetworkChanged(
45 net::NetworkChangeNotifier::ConnectionType type) override;
46
47 void StartOnIOThread();
48 void ScheduleRestart();
49 void Restart(const net::NetworkInterfaceList& networks);
50 int Bind();
51 bool IsSourceAcceptable() const;
52 bool IsPrivetPacket(int rv) const;
53 int DoLoop(int rv);
54
55 base::Closure on_traffic_detected_;
56 scoped_refptr<base::TaskRunner> callback_runner_;
57 net::NetworkInterfaceList networks_;
58 net::AddressFamily address_family_;
59 net::IPEndPoint recv_addr_;
60 scoped_ptr<net::DatagramServerSocket> socket_;
61 scoped_refptr<net::IOBufferWithSize> io_buffer_;
62 base::Time start_time_;
63 int restart_attempts_;
64
65 base::WeakPtrFactory<PrivetTrafficDetector> weak_ptr_factory_;
66
67 DISALLOW_COPY_AND_ASSIGN(PrivetTrafficDetector);
68 };
69
70 } // namespace local_discovery
71
72 #endif // CHROME_BROWSER_LOCAL_DISCOVERY_PRIVET_TRAFFIC_DETECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698