Closed Bug 1564120 Opened 5 years ago Closed 2 years ago

Make nsHttpConnectionInfo immutable, mutability only via a 'mutator' as in the URI case

Categories

(Core :: Networking: HTTP, task, P2)

task

Tracking

()

RESOLVED WONTFIX
Tracking Status
firefox69 --- affected

People

(Reporter: mayhemer, Assigned: kershaw, Mentored)

Details

(Whiteboard: [necko-triaged])

Attachments

(1 file, 3 obsolete files)

No description provided.

Bugbug thinks this bug is a task, but please change it back in case of error.

Type: defect → task
Priority: -- → P2
Whiteboard: [necko-triaged]

Hello @Honza
I would like to work on this !!
It would be great if you can explain this a bit more :)
thanks

Flags: needinfo?(honzab.moz)

Thanks for the offer of help.

The idea is to make all Set* methods of nsHttpConnectionInfo private-friend to a newly written "mutor" helper class. The mutator will have a mirror of all the Set* methods, public. It will create a clone of the given nsHttpConnectionInfo, modify this clone, and spit it out with a method alreaday_AddRefed<nsHttpConnectionInfo> Finalize(). Since then any Set* method call on the mutator will fail, best by throwing the reference to the nsHttpConnectionInfo object away. The Clone method of nsHttpConnectionInfo should also be made private or simply removed, when found fit.

Then, on all places where nsHttpConnectionInfo is modified by one of its Set* methods in our current code base (will simply pop-up during the build as an error when made private), replace it to use the mutator.

Flags: needinfo?(honzab.moz)

hey @Honza Bambas
You said I need to create class mutor(or mutator ?) . so it should be inside nsHttpConnectionInfo or outside it ?
How should I create it ? Can you explain a bit ?
and I need to create all set* functions like this inside mutor class ?
friend void nsHttpConnectionInfo::SetAnonymous(bool anon);
And what do you mean by clone of the given nsHttpConnectionInfo?

Flags: needinfo?(honzab.moz)

It's mostly about turning this:

class nsHttpConnectionInfo {
public:
  void SetFoo(Foo foo);
  Foo GetFoo();
private:
  Foo mFoo;
};

into something like this (not with necessarily the methods being inline):

class nsHttpConnectionInfo {
public:
  Foo GetFoo();

  Mutator {
  public:
    Mutator(nsHttpConnectionInfo* ci) {
      mCI = ci->Clone();
    }

    void SetFoo(Foo foo) {
      mCI->mFoo = foo; // this will work becaues nested classes see private members
    }
    
    already_AddRefed<nsHttpConnectionInfo> Finalize() {
      return mCI.forget();
    }

  private:
    RefPtr<nsHttpConnectionInfo> mCI;
  };

private:
  Foo mFoo;
};

the use of the Mutator is I believe obvious?

Flags: needinfo?(honzab.moz)

@Honza
Got it and will submit the patch as soon as possible :)
Thanks for help !!

hey @honza
Can you help me with this error

 /home/mahak/mozilla-central/netwerk/protocol/http/TRRServiceChannel.cpp:391:22: error: no member named 'SetNoSpdy' in 'mozilla::net::nsHttpConnectionInfo'
 0:05.73     mConnectionInfo->SetNoSpdy(true);

how do I change this using mutator class ?

@Honza
Should I submit the patch so that you can guide me in a better way ?

(In reply to Mahak from comment #8)

@Honza
Should I submit the patch so that you can guide me in a better way ?

Yes, I think it'd be good to submit your WIP patch.

Not sure whom to add as the reviewer ?

Assignee: nobody → mbansal
Status: NEW → ASSIGNED
Mentor: valentin.gosu

Hi Mahak,

I'd like to work on this one.
Please let me know if you'd like to continue with this.

Thank you.

Flags: needinfo?(mbansal)

Hi Kershaw!
Go ahead. I'm not working on this anymore
Thanks :)

Flags: needinfo?(mbansal)
Assignee: mbansal → kershaw

Depends on D91905

Attachment #9178674 - Attachment is obsolete: true
Attachment #9178675 - Attachment is obsolete: true
Attachment #9178676 - Attachment is obsolete: true

I think this is a WONTFIX, since copying a connection info every time introduce some extra performance overhead.

Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → WONTFIX
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: